Set custom properties using reflection on custom UserControl
I need to use reflection to set two custom propertys of custom userControls
CustomUserControl.cs
......
public string _ValidaMsg get return _ValidarMsg; set _ValidarMsg = value;
public bool _Valida get return _Validar; set _Validar = value;
._Valida determinates if the control needs to be validated before submitting the form
and ._ValidaMsg is the message it shows when the field isn't completed
In my form.cs I have a typed List called listaMetodo (String ControlName,String ControlText,Type Control.Type) Here's the method where I fill my list
private List<xEntidades.entControlValidacion> GetAllControls(Control container)
foreach (Control c in container.Controls)
c.Name.Equals("txtFecha"))
listaMetodo.Add(new xEntidades.entControlValidacion(c.Parent.Name, c.Text, c.GetType()));
return listaMetodo;
So once I have the list with all controls that are relevant, what I need to do is to compare it with another that I have, wich is filled with all the controls that needs to be validated, let's call it validateList(string NameOfControl,bool Valida , String ValidaMsg).
In the for loop while im itherating the two list I have the condition
If(listaMetodo[iExample].ControlName.equals(validateList[jExample].NameOfControl && validateList[jExample].Valida)
//here I should get the instance of the object by reflection and change ._ValidaMsg and ._Valida
So, how can I Modify the propertys of the instanced object using the Type and the ControlName Stored in my listaMetodo
It's mandatory to use reflection? Is there another approatch to achieve what I wat to?
Also Im Working with Framework 2.0
Thanks in Advance
c# reflection
add a comment |
I need to use reflection to set two custom propertys of custom userControls
CustomUserControl.cs
......
public string _ValidaMsg get return _ValidarMsg; set _ValidarMsg = value;
public bool _Valida get return _Validar; set _Validar = value;
._Valida determinates if the control needs to be validated before submitting the form
and ._ValidaMsg is the message it shows when the field isn't completed
In my form.cs I have a typed List called listaMetodo (String ControlName,String ControlText,Type Control.Type) Here's the method where I fill my list
private List<xEntidades.entControlValidacion> GetAllControls(Control container)
foreach (Control c in container.Controls)
c.Name.Equals("txtFecha"))
listaMetodo.Add(new xEntidades.entControlValidacion(c.Parent.Name, c.Text, c.GetType()));
return listaMetodo;
So once I have the list with all controls that are relevant, what I need to do is to compare it with another that I have, wich is filled with all the controls that needs to be validated, let's call it validateList(string NameOfControl,bool Valida , String ValidaMsg).
In the for loop while im itherating the two list I have the condition
If(listaMetodo[iExample].ControlName.equals(validateList[jExample].NameOfControl && validateList[jExample].Valida)
//here I should get the instance of the object by reflection and change ._ValidaMsg and ._Valida
So, how can I Modify the propertys of the instanced object using the Type and the ControlName Stored in my listaMetodo
It's mandatory to use reflection? Is there another approatch to achieve what I wat to?
Also Im Working with Framework 2.0
Thanks in Advance
c# reflection
add a comment |
I need to use reflection to set two custom propertys of custom userControls
CustomUserControl.cs
......
public string _ValidaMsg get return _ValidarMsg; set _ValidarMsg = value;
public bool _Valida get return _Validar; set _Validar = value;
._Valida determinates if the control needs to be validated before submitting the form
and ._ValidaMsg is the message it shows when the field isn't completed
In my form.cs I have a typed List called listaMetodo (String ControlName,String ControlText,Type Control.Type) Here's the method where I fill my list
private List<xEntidades.entControlValidacion> GetAllControls(Control container)
foreach (Control c in container.Controls)
c.Name.Equals("txtFecha"))
listaMetodo.Add(new xEntidades.entControlValidacion(c.Parent.Name, c.Text, c.GetType()));
return listaMetodo;
So once I have the list with all controls that are relevant, what I need to do is to compare it with another that I have, wich is filled with all the controls that needs to be validated, let's call it validateList(string NameOfControl,bool Valida , String ValidaMsg).
In the for loop while im itherating the two list I have the condition
If(listaMetodo[iExample].ControlName.equals(validateList[jExample].NameOfControl && validateList[jExample].Valida)
//here I should get the instance of the object by reflection and change ._ValidaMsg and ._Valida
So, how can I Modify the propertys of the instanced object using the Type and the ControlName Stored in my listaMetodo
It's mandatory to use reflection? Is there another approatch to achieve what I wat to?
Also Im Working with Framework 2.0
Thanks in Advance
c# reflection
I need to use reflection to set two custom propertys of custom userControls
CustomUserControl.cs
......
public string _ValidaMsg get return _ValidarMsg; set _ValidarMsg = value;
public bool _Valida get return _Validar; set _Validar = value;
._Valida determinates if the control needs to be validated before submitting the form
and ._ValidaMsg is the message it shows when the field isn't completed
In my form.cs I have a typed List called listaMetodo (String ControlName,String ControlText,Type Control.Type) Here's the method where I fill my list
private List<xEntidades.entControlValidacion> GetAllControls(Control container)
foreach (Control c in container.Controls)
c.Name.Equals("txtFecha"))
listaMetodo.Add(new xEntidades.entControlValidacion(c.Parent.Name, c.Text, c.GetType()));
return listaMetodo;
So once I have the list with all controls that are relevant, what I need to do is to compare it with another that I have, wich is filled with all the controls that needs to be validated, let's call it validateList(string NameOfControl,bool Valida , String ValidaMsg).
In the for loop while im itherating the two list I have the condition
If(listaMetodo[iExample].ControlName.equals(validateList[jExample].NameOfControl && validateList[jExample].Valida)
//here I should get the instance of the object by reflection and change ._ValidaMsg and ._Valida
So, how can I Modify the propertys of the instanced object using the Type and the ControlName Stored in my listaMetodo
It's mandatory to use reflection? Is there another approatch to achieve what I wat to?
Also Im Working with Framework 2.0
Thanks in Advance
c# reflection
c# reflection
edited Dec 6 '18 at 13:42
JoaquinAlvarez
asked Nov 13 '18 at 11:20
JoaquinAlvarezJoaquinAlvarez
469114
469114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Well finally I achieved what i wanted creating this method
private void validaControles()
for (int j = 0; j < listaMetodo.Count; j++)
for (int k = 0; k < listaControlesValida.Count; k++)
//just ignore this condition
if(listaMetodo[j].NombrePadre.Equals(listaControlesValida[k].Control) && listaControlesValida[k].Valida && listaMetodo[j].TextoControl.Equals(""))
listaControlesValida[k].ValidaText, null);
Control control = this.Controls.Find(listaMetodo[j].NombrePadre, true);
Type type = control[0].GetType();
control[0].GetType().GetProperty("_ValidaMsg").SetValue(control[0], listaControlesValida[k].ValidaText, null);
control[0].GetType().GetProperty("_Valida").SetValue(control[0], true, null);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279912%2fset-custom-properties-using-reflection-on-custom-usercontrol%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Well finally I achieved what i wanted creating this method
private void validaControles()
for (int j = 0; j < listaMetodo.Count; j++)
for (int k = 0; k < listaControlesValida.Count; k++)
//just ignore this condition
if(listaMetodo[j].NombrePadre.Equals(listaControlesValida[k].Control) && listaControlesValida[k].Valida && listaMetodo[j].TextoControl.Equals(""))
listaControlesValida[k].ValidaText, null);
Control control = this.Controls.Find(listaMetodo[j].NombrePadre, true);
Type type = control[0].GetType();
control[0].GetType().GetProperty("_ValidaMsg").SetValue(control[0], listaControlesValida[k].ValidaText, null);
control[0].GetType().GetProperty("_Valida").SetValue(control[0], true, null);
add a comment |
Well finally I achieved what i wanted creating this method
private void validaControles()
for (int j = 0; j < listaMetodo.Count; j++)
for (int k = 0; k < listaControlesValida.Count; k++)
//just ignore this condition
if(listaMetodo[j].NombrePadre.Equals(listaControlesValida[k].Control) && listaControlesValida[k].Valida && listaMetodo[j].TextoControl.Equals(""))
listaControlesValida[k].ValidaText, null);
Control control = this.Controls.Find(listaMetodo[j].NombrePadre, true);
Type type = control[0].GetType();
control[0].GetType().GetProperty("_ValidaMsg").SetValue(control[0], listaControlesValida[k].ValidaText, null);
control[0].GetType().GetProperty("_Valida").SetValue(control[0], true, null);
add a comment |
Well finally I achieved what i wanted creating this method
private void validaControles()
for (int j = 0; j < listaMetodo.Count; j++)
for (int k = 0; k < listaControlesValida.Count; k++)
//just ignore this condition
if(listaMetodo[j].NombrePadre.Equals(listaControlesValida[k].Control) && listaControlesValida[k].Valida && listaMetodo[j].TextoControl.Equals(""))
listaControlesValida[k].ValidaText, null);
Control control = this.Controls.Find(listaMetodo[j].NombrePadre, true);
Type type = control[0].GetType();
control[0].GetType().GetProperty("_ValidaMsg").SetValue(control[0], listaControlesValida[k].ValidaText, null);
control[0].GetType().GetProperty("_Valida").SetValue(control[0], true, null);
Well finally I achieved what i wanted creating this method
private void validaControles()
for (int j = 0; j < listaMetodo.Count; j++)
for (int k = 0; k < listaControlesValida.Count; k++)
//just ignore this condition
if(listaMetodo[j].NombrePadre.Equals(listaControlesValida[k].Control) && listaControlesValida[k].Valida && listaMetodo[j].TextoControl.Equals(""))
listaControlesValida[k].ValidaText, null);
Control control = this.Controls.Find(listaMetodo[j].NombrePadre, true);
Type type = control[0].GetType();
control[0].GetType().GetProperty("_ValidaMsg").SetValue(control[0], listaControlesValida[k].ValidaText, null);
control[0].GetType().GetProperty("_Valida").SetValue(control[0], true, null);
answered Nov 13 '18 at 12:41
JoaquinAlvarezJoaquinAlvarez
469114
469114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279912%2fset-custom-properties-using-reflection-on-custom-usercontrol%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown