Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET access non-server controls inside Panel

I've got a custom control that inherits from Panel. At Load-time, I want to access all of the controls inside of this panel, including non-server controls, to manipulate the attributes. The Controls property of the panel gives me the server controls, but not the non-server ones. Is there any way to access them?

For example:

<cc:MyPanel runat="server">
    <asp:TextBox id="txt1" runat="server" />
    <input type="text" id="txt2" />
</cc:MyPanel>

During the Load event (or really any event before the control is rendered), I want to manipulate both text boxes.

Thanks

like image 514
Joe Enos Avatar asked May 10 '26 16:05

Joe Enos


1 Answers

You'd have to either add runat='server' on each tag or do some JavaScript to handle this. The load event is looking at server controls.

Change your control to:

<input id="txt2" runat="server" type="text" />

Then you can do:

string s = txt2.Text;

The only other way I can think of is if you wanted to actually use a form to post the values and then use Request. to access each variable that you are posting. But my thought is you are looking more for the former rather then the latter.

Finally if you go the JS route here is a nice article from MSDN showing you how to do this: http://msdn.microsoft.com/en-us/library/3hc29e2a.aspx

like image 50
JonH Avatar answered May 12 '26 06:05

JonH