page = (Page)HttpContext.Current.CurrentHandler;
TextBox txtEndUser = ((TextBox)page.FindControl("txtEndUser"));
Here txtEndUser
always comes as null.
How can we fix this ?
page = (Page)HttpContext.Current.CurrentHandler;
TextBox txtEndUser = ((TextBox)page.FindControl("txtEndUser"));
Here txtEndUser
always comes as null.
How can we fix this ?
If the page does not directly contains the TextBox
control, then you wont be able to retrieve it with the FindControl
function. You need to create a function that search contained containers for the target control ..
It appears to me that this code snippet is in HttpModule
so probably, the request has not been handed out to a handler yet (for example, you're in BeginRequest
).
Reference: Why HttpContext.Current.Handler is null?
As a workaround if you don't find the way using FindControl
you can add public getter to your custom page class the have something like this:
WebForm1 myForm = (WebForm1)HttpContext.Current.CurrentHandler;
TextBox txtEndUser = myForm.GetEndUserTextbox();