0

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!

V. Israni
  • 13
  • 6
  • https://stackoverflow.com/a/20882549/8736208 u need to search better before open a new issue. – Er.Er Oct 18 '17 at 08:24
  • @Er.Er the link you have provided does not solve my problem. I have not made it null anywhere in my code. I just want to access it and have some value in it. And also it is not in normal (aspx page), this text box is in user control (ascx page). – V. Israni Oct 18 '17 at 08:34
  • Where is `textbox1.text = "ABC";`? – wazz Oct 19 '17 at 02:33
  • @wazz it is in Page_Load event of User Control page(.ascx). – V. Israni Oct 23 '17 at 07:21
  • This might not do anything but is 'text' with a capital T? Try `textbox1.Text`. – wazz Oct 23 '17 at 07:31

2 Answers2

1

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" %>
wazz
  • 4,953
  • 5
  • 20
  • 34
0

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