Text box Control not getting initialized inside UserControl(.ascx page)

457 Views Asked by At

I have textbox inside a user control(ascx page) like this :

<asp:TextBox ID="textbox1" runat="server" PlaceHolder="Practice Name"></asp:TextBox>

Now when I try to access this textbox from code behind, it is not getting initialized and shows as null.

textbox1.text = "ABC";

The above statement should assign textbox1's text as "ABC" but it is showing as null and gives an error object reference not set to an instance of an object.

Please help!

2

There are 2 best solutions below

0
On

try to create another textbox drag and drop .. Place holder could make some issue in implementing asp controls.

0
On

Make sure your user control is registered on the aspx page that's using it. At the top should be something like

<%@ Register Src="~/Controls/MyCtrl.ascx" TagName="MyCtrl" TagPrefix="xyz" %>