Updating Controls included in other controls
-
I have a user control that i created which contains a bunch of search varibles in the form of text boxes and drop-down lists. I include this control in the search page and a couple of others. I am trying to update the value of the textbox and drop down lists within this user control and can't. I have been able to read the values of the Controls using:
Control myKeywords = FindControl("ctl_search:tb_keywords"); TextBox tb_keywords = (TextBox)myKeywords; tb_keywords.Text.ToString();
But I need to update the value of those controls. Any help you can provide would be greatly appreciated! -
I have a user control that i created which contains a bunch of search varibles in the form of text boxes and drop-down lists. I include this control in the search page and a couple of others. I am trying to update the value of the textbox and drop down lists within this user control and can't. I have been able to read the values of the Controls using:
Control myKeywords = FindControl("ctl_search:tb_keywords"); TextBox tb_keywords = (TextBox)myKeywords; tb_keywords.Text.ToString();
But I need to update the value of those controls. Any help you can provide would be greatly appreciated!Why are you using
Text.ToString
?Text
already returns a string. This is a waste of CPU cycles. If you're getting back a value (i.e., notnull
) fromFindControl
, then just set cast to aTextBox
as you're doing and setText
to some string, liketb_keywords.Text = "Some string";
.Microsoft MVP, Visual C# My Articles