c# - Why can Controls be found on an OnClick Event, but not in Page Load? -


so i'm assuming has page lifecycle, , maybe controls aren't yet bound on page load? i'm still learning asp.net page lifecycle, when binding occurs, when can access data , when it's early/late, etc. i'd explanation on why following won't work. assuming method recursively searches controls, beginning repeateritem, looking textbox, so...

 private void findmytextbox()  {     foreach (repeateritem repeated in myrepeater.items)     {         textbox txtpercentage = (textbox)findcontrolrecursive(repeated, "txtpercentage");         .         .         .     }  } 

....where....

public static control findcontrolrecursive(control root, string id) {     if (root.id == id)     {         return root;     }      return root.controls.cast<control>()         .select(c => findcontrolrecursive(c, id))         .firstordefault(c => c != null); } 

...why work called method bound onclick event, like....

<asp:button id="btnsubmit" runat="server" text="submit" onclick="validate" />   protected void validate(object sender, eventargs e)  {      findmytextbox();  } 

...but not when called page_load, like....

protected void page_load(object sender, eventargs e) {     findmytextbox(); } 


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -