Access all controls on ASP.Net form

  • Thread starter Thread starter pargat.singh
  • Start date Start date
P

pargat.singh

HI Everyone:

I have a asp.net page with all the controls as below and i need to
access all these on_load because i need to set their values from
database.

Some how i can not access the controls under UpdatePanel. Is there any
generic way to access all the controls from the page no matter if they
are under other controls like under panel etc.

Please help.

Gill


<form id="frmPaymentCalculator" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table border="0" width="700px">
<tr>
<td style="width: 700px">
<asp:Panel ID="generic"
runat="server">
<asp:Label
ID="rifpaymentCalculator" runat="server" CssClass="PageTitle"></
asp:Label><br />
<br />
<asp:ValidationSummary ID="valSum"
runat="server" HeaderText="" DisplayMode="SingleParagraph" />
</asp:Panel>
<asp:Panel ID="pnl1" runat="server"
Width="700px">
<asp:Label CssClass="PageHint"
ID="rifpaymentCalculatorDesc" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="rrif"
runat="server" CssClass="Bold Hint"></asp:Label>
<asp:Label ID="rrifDash"
runat="server" Text=" - "></asp:Label>
<asp:Label ID="rrifDesc"
runat="server" CssClass="PageHint"></asp:Label><br />
<asp:Label ID="rrifDesc2"
runat="server" CssClass="PageHint"></asp:Label>
<br />
<br />
<asp:Label ID="lif" runat="server"
CssClass="Bold Hint"></asp:Label>
<asp:Label ID="lifDash"
runat="server" Text=" - "></asp:Label>
<asp:Label ID="lifDesc"
runat="server" CssClass="PageHint"></asp:Label><br />
<asp:Label ID="lifDesc2"
runat="server" CssClass="PageHint"></asp:Label>
<br />
<br />
<asp:Label ID="lrif"
runat="server" CssClass="Bold Hint"></asp:Label>
<asp:Label ID="lrifDash"
runat="server" Text=" - "></asp:Label>
<asp:Label ID="lrifDesc"
runat="server" CssClass="PageHint"></asp:Label><br />
<asp:Label ID="lrifDesc2"
runat="server" CssClass="PageHint"></asp:Label>
<br />
<br />
<asp:Label ID="prif"
runat="server" CssClass="Bold Hint"></asp:Label>
<asp:Label ID="prifDash"
runat="server" Text=" - "></asp:Label>
<asp:Label ID="prifDesc"
runat="server" CssClass="PageHint"></asp:Label><br />
<asp:Label ID="prifDesc2"
runat="server" CssClass="PageHint"></asp:Label>
<br />
<br />
<asp:Label ID="disclaimer"
runat="server" CssClass="Bold Hint"></asp:Label>
<asp:Label ID="disclaimerDesc"
runat="server" CssClass="PageHint"></asp:Label>
<br />
<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnNext"
runat="server" CssClass="BUTTON" Width="83px" OnClick="btnNext_Click" /
</asp:Panel>
<br />
</td>
</tr>
<tr>
<td style="width: 700px">
<asp:Panel ID="pnl2" Visible="false"
runat="server" Height="550px" Width="700px">
<fieldset>
<table border="0"
width="100%">
<tr>
<td style="width:
50%">
<asp:Label
CssClass="LabelFont" ID="lblEmpProvince" Width="100%" runat="server"></
asp:Label></td>
<td style="width: 50%"
align="right">
<asp:DropDownList
Width="70%" ID="lstEmpProvince" runat="server" AutoPostBack="True">
</
asp:DropDownList>
</td>
</tr>
<tr>
<td style="width:
50%">
<asp:Label
Width="100%" ID="lblCountryofResidenceAtRetirem" runat="server"
CssClass="LabelFont"></asp:Label>
</td>
<td style="width: 50%"
align="right">
<asp:DropDownList
Width="70%" ID="lstRetCountry" AutoPostBack="true" runat="server">
</
asp:DropDownList>
</td>
</tr>
<tr>
<td style="width:
50%">
<asp:Label
Width="100%" ID="lblProvinceOfResidenceAtRetire" runat="server"
CssClass="LabelFont"></asp:Label>
</td>
<td style="width: 50%"
align="right">
<asp:DropDownList
Width="70%" ID="lstRetProvince" runat="server">
</
asp:DropDownList>
</td>
</tr>
</table>
</fieldset>
<br />
<asp:Label ID="lblDatesHint"
runat="server"></asp:Label>
</asp:Panel>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
 
HI Everyone:

I have a asp.net page with all the controls as below and i need to
access all these on_load because i need to set their values from
database.

Some how i can not access the controls under UpdatePanel. Is there any
generic way to access all the controls from the page no matter if they
are under other controls like under panel etc.

Please help.

If can't remember exactly but you can loop through the controls on an ASP
page like this.

for each x as Webcontrol
dim test as string = x.name
next

You should be able to walk the page and look at the properties of each
Webcontrol. You should be able to set them too.

If x.name = "txtDept" then
x.Text = "Dept1"
end if

It's a VB example, but you should be able to do the same in C#.
 
Back
Top