Find Control on webform
-
Hi, I have a button on my webform that I need to access from my user control code behind, not the page on which the button resides, but I'm not sure how I find it. I've thought it would be something like this, but this doesnt work: Button button=(Button)FindControl("btn"); Thanks!
-
Hi, I have a button on my webform that I need to access from my user control code behind, not the page on which the button resides, but I'm not sure how I find it. I've thought it would be something like this, but this doesnt work: Button button=(Button)FindControl("btn"); Thanks!
-
Yes have tried that: Button button=(Button)Page.FindControl("btn"); The Page will return the correct page, but nothing gets assigned to button, so I am getting nullReferenceException error.
-
Yes have tried that: Button button=(Button)Page.FindControl("btn"); The Page will return the correct page, but nothing gets assigned to button, so I am getting nullReferenceException error.
I hope that Button is not in the ContentPlaceHolder and you are not using MasterPages. Try
Page.Parent.FindControl()
If that button is inside the ContentPlaceHolder then stack trace and find the actual value for that button. something like xxxxxctl001_btn. then first find the content place holder (or any other container) usingcontainer c = Page.FindControl('container')
and thenc.FindControl('btn')
PS: container means any container i.e. Panel / ContentPlaceHolder etc... -
I hope that Button is not in the ContentPlaceHolder and you are not using MasterPages. Try
Page.Parent.FindControl()
If that button is inside the ContentPlaceHolder then stack trace and find the actual value for that button. something like xxxxxctl001_btn. then first find the content place holder (or any other container) usingcontainer c = Page.FindControl('container')
and thenc.FindControl('btn')
PS: container means any container i.e. Panel / ContentPlaceHolder etc...