c# - asp.net Label cannot ever be modified from code-behind -
i have panel/updatepanel contains asp.net label. seems under no circumstances whatsoever text field of control can changed. code:
<asp:panel runat="server" id="panel1" width="100%"> <asp:updatepanel runat="server" id="updroutegroup" updatemode="conditional"> <triggers> <asp:postbacktrigger controlid="btndisableonhold" /> </triggers> <contenttemplate> <asp:panel id="pnlimpexcel" runat="server" > <div style="width:100%"> <table colspan="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <th colspan="3"> on hold music </th> </tr> <tr style="height:10px"></tr> <tr> <td align="left" valign="middle" style="width:33%"><div id="fine-uploader"></div></td> <td align="center" valign="middle"><asp:label id="lblonholdfile" runat="server" text="current file: none" /></td> <td align="right" valign="middle"><asp:button id="btndisableonhold" runat="server" style="margin-right:7px;width:87px;" text="disable hold music" cssclass="button" onclick="btndisableonhold_onclick" /></td> </tr> <tr><td colspan ="2" align="center"><asp:label runat="server" id="lbluploaderror" style="color: red;" visible="false" /></td></tr> </table> </div> </asp:panel> </contenttemplate> </asp:updatepanel> </asp:panel>
when postback occurs might need update this, check conditions , attempt modify text doing:
protected void page_load(object sender, eventargs e) { if (this.page.ispostback) lblonholdfile.text = "some text."; }
this code bad, i've little experience asp.net , have inherited project. still cannot understand point of exposing these labels in code-behind if cannot modify them @ all. how can set .text field of control lblonholdfile? thanks.
here what's in btndisablehold_onclick:
protected void btndisableonhold_onclick(object sender, eventargs e) { //update records // clear out existing file label: lblonholdfile.text = "current file: none"; }
that problem, line:
lblonholdfile.text = "current file: none";
you have undone text change made in page_load
above line in click event handler.
the text
property of label got changed twice; once some text
in page_load
, original value in btndisableonhold_onclick
method. makes appear setting text
value nothing, when in reality changed.
update:
to have javascript create postback code, need invoke __dopostback
function.
Comments
Post a Comment