How can I retrieve the form elements on serverside in dotnet

satya - Wednesday, May 16, 2007 1:23:35 PM

related article from odetocode

related article from odetocode

satya - Wednesday, May 16, 2007 1:26:51 PM

example


<form id="Form1" method="post" runat="server">
  <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
  <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>

private void Button1_Click(object sender, System.EventArgs e)
{
   TextBox b = Page.FindControl("TextBox1") as TextBox;
   if(b != null)
   {
      Response.Write("Found TextBox1 on Button1_Click<br>");
   }         
}

satya - Wednesday, May 16, 2007 1:32:22 PM

See what happens to a control inside a dataview header


<input name="ctl00$aspireContent$wellGrid$ctl01$wellName" 
type="text" 
id="ctl00_aspireContent_wellGrid_ctl01_wellName" 
style="display:block;" />

My original name I gave to this text control is "wellname".

satya - Wednesday, May 16, 2007 1:32:50 PM

wonder if there is a way to force a name outside a naming container

wonder if there is a way to force a name outside a naming container

satya - Wednesday, May 16, 2007 1:47:36 PM

To locate a control by name you need to know the hierarchy of controls

To locate a control by name you need to know the hierarchy of controls

satya - Wednesday, May 16, 2007 1:48:02 PM

wonder if findcontrol can traverse for a unique in all its children?

wonder if findcontrol can traverse for a unique in all its children?

satya - Wednesday, May 16, 2007 1:53:42 PM

well there is always a way


private Control FindControlRecursive(Control root, string id) 
{ 
    if (root.ID == id)
    { 
        return root; 
    } 

    foreach (Control c in root.Controls) 
    { 
        Control t = FindControlRecursive(c, id); 
        if (t != null) 
        { 
            return t; 
        } 
    } 

    return null; 
}

satya - Wednesday, May 16, 2007 1:54:43 PM

The above is borrowed from

The above is borrowed from

satya - Thursday, May 17, 2007 10:20:04 AM

Viewstate and dynamically added controls

Viewstate and dynamically added controls