单击按钮后更新文本框

本文关键字:文本 更新 按钮 单击 | 更新日期: 2023-09-27 18:14:21

我有这个TextBox:

<asp:TextBox id="locSelectedCameraGroupName" runat="server" ></asp:TextBox>

我有这个后端代码:

protected void btnCameraGroup_ServerClick(object sender, EventArgs e)
{
    locSelectedCameraGroupName.Text = "test string!";
}

此方法在单击按钮后调用:

<asp:linkbutton id="btnCameraGroup" runat="server" onclick="btnCameraGroup_ServerClick" onclientclick="ShowCameraGroupPopup()"
    style="font-size: 1.2em; text-decoration: none; cursor: pointer; background-color:grey; "> 
<!-- TODO:  Make button have round corners...css? -->
</asp:linkbutton>

然而,文本没有更新。这是一个用户控件。到达该行(根据我的调试器)。当我将这行移动到页面加载时,它就工作了。我做错了什么吗?

下面的方法ShowCameraGroupPopup只是显示/隐藏一些标签,我不认为它有太多的问题,但这里是无论如何:

function ShowCameraGroupPopup() {
    $('#<%=waitIcon.ClientID%>').show();
    $('#<%=divMainContent.ClientID%>').hide();
    $("#divCameraGroupPopup").modal("show");
    return true;
}

点击链接按钮后的流程:

  1. Page_Load hit (is post back)
  2. btnCameraGroup_ServerClick hit
  3. 选项卡名称=第二个选项卡(这是我想要的信息,但由于某种原因文本未更新)

单击按钮后更新文本框

我需要一个带有触发器(AsyncPostBackTrigger)的TextBox周围的UpdatePanel(和ContentTemplate):

<asp:UpdatePanel id="groupNamePanel" runat="server" updatemode="Conditional"> 
     <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnCameraGroup" />
    </Triggers>
    <ContentTemplate>
        <asp:TextBox id="locSelectedCameraGroupName" runat="server" ></asp:TextBox>
    </ContentTemplate>
</asp:UpdatePanel>

如果你的代码中有Page_Load()事件,修改Page_Load()内容,如下所示:

private void Page_Load()
{
    if (!Page.IsPostBack)
    {
        //copy previous page load codes here
    }
}