c# - populating a text box with FindControl -
i have multiple textboxes , want programatically populate them same method.
<asp:content id="content2" contentplaceholderid="contentplaceholder1" runat="server"> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <asp:updateprogress id="updateprogress1" runat="server" displayafter="500"> <progresstemplate> <div id="freezeupdate" class="freezepaneon"> <div id="innerfreezepane" class="innerfreezepane gradient"><asp:literal id="litprogress" runat="server" text="<%$ resources:localizedtext, freezemsg_processingpleasewait %>"></asp:literal></style></div> </div> </progresstemplate> </asp:updateprogress> <asp:updatepanel id="updatepanel1" runat="server"> <asp:textbox id="tbxcollectionaddress" runat="server" textmode="multiline" readonly="true" cssclass="address"></asp:textbox> <asp:textbox id="tbxreturnaddress" runat="server" textmode="multiline" readonly="true" cssclass="address"></asp:textbox> </asp:updatepanel> </asp:content>
then method...
protected void populateaddress(string txttextbox, address adraddress) { textbox txtaddress = (textbox)findcontrol(txttextbox); txtaddress.text = "hello world"; }
when call method below...
populateaddress("tbxreturnaddress", collectionaddress);
...i exception...
system.nullreferenceexception: object reference not set instance of object.
...and highlights txtaddress.text = "hello world";
line.
i'd like method because there 3 separate addresses need populate on form i'd try using re-usable code feeding in address object , textbox id, i'm falling on @ findcontrol stage.
what missing?
firstly , test function likes
textbox txtaddress = (textbox)findcontrol("tbxreturnaddress");
or
you can try likes ,
textbox txtaddress = (textbox)page.findcontrol("tbxreturnaddress");
edit
if text-box in updatepanel
,
textbox txtaddress = (textbox)updatepanel1.findcontrol("tbxreturnaddress");
Comments
Post a Comment