Updating Label inside UpdatePanel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 18:58:14

问题


i have a label and button inside update panel, when i try to get the value from the label on the button click, i get the value from label, but when i try to set the value to the label, it does not happens, i checked for JavaScript error, but there wasn't any, does anyone have any guess what could be the reason. i am using dotnetnuke and here is my code

<asp:UpdatePanel ID="updSection6" runat="server"><ContentTemplate>
<asp:Label ID="lbl" runat="server" />
<asp:ImageButton ImageUrl="/images/edit.gif" ID="btnEditSectionStory6" runat="server" OnClick="Clicked" />
</ContentTemplate></asp:UpdatePanel>

and here's the code

protected void Clicked(object sender, EventArgs e)
{
   lbl.Text="Welcome";
}

回答1:


You need to add the following code

<Triggers>
    <asp:PostBackTrigger ControlID="btnEditSectionStory6" />
</Triggers>

Just before your closing </asp:UpdatePanel>

So your code should look like:

<asp:UpdatePanel ID="updSection6" runat="server">
    <ContentTemplate>
        <asp:Label ID="lbl" runat="server" />
        <asp:ImageButton ImageUrl="/images/edit.gif" ID="btnEditSectionStory6" runat="server" OnClick="Clicked" />
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnEditSectionStory6" />
    </Triggers>
</asp:UpdatePanel>

ASP PostBackTrigger

Specifies a control and event that will cause a full page update (a full page refresh). This tag can be used to force a full refresh when a control would otherwise trigger partial rendering.

You can read more about UpdatePanel's and Triggers here.

C# (using the ImageClickEventArgs)

    protected void Clicked(object sender, ImageClickEventArgs e)
    {
        lbl.Text = "Welcome";
    }


来源:https://stackoverflow.com/questions/9935295/updating-label-inside-updatepanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!