简体   繁体   English

ASP:标签未在按钮上更新单击

[英]ASP:Labels not updating on button Click

I know this is probably something so simple that I am just not able to see it. 我知道这可能很简单,以至于我看不到它。 I have an aspx form that has a usercontrol in an updata panel. 我有一个aspx表单,在updata面板中有一个usercontrol。 The user control is a people picker the searches on users from a corporate database. 用户控件是人员选择器,用于从公司数据库中搜索用户。

What I want to see happen is: 我想看到的是:

  1. The user clicks on a pick user button 用户单击选择用户按钮
  2. The update panel with people picker becomes visible 带有人员选择器的更新面板变为可见
  3. They search for a user and then select the one they want. 他们搜索用户,然后选择所需的用户。
  4. When they make the selection and click Done, I get the user id of the user and look them up in our user table. 当他们做出选择并单击“完成”时,我获得了该用户的用户ID并在我们的用户表中查找它们。
  5. The user information should show up in a the form in label fields. 用户信息应以标签字段的形式显示。

I can step through the code and see that I am getting the user information and that the label text is being set to the values but the page never updates the labels. 我可以单步执行代码,查看是否正在获取用户信息,并且标签文本已设置为值,但是页面从未更新标签。 It is a postback so I would think they would update. 这是回发,所以我认为它们会更新。

<tr>
        <td colspan="4">
            <asp:UpdatePanel ID="CollapseDelegate" runat="server">
                <ContentTemplate>
                    <asp:Panel ID="pDelegateHeader" runat="server">
                        <div style="padding: 10px 0 10px 20px; height:10px;  text-align: left; background-color:#ffffff; color:#000000; border: 2px solid #ccc;"  >
                            <asp:Label ID="ShowDelegate" runat="server" /><br />
                        </div>
                    </asp:Panel>
                    <asp:Panel ID="pDelegateBody" runat="server">
                        <PP:PeoplePicker ID="PP" runat="server" />
                        <asp:Button ID="btnOk" runat="server" Text="Done" CssClass="Buttons" onclick="btnOk_Click" /> 
                    </asp:Panel>
                    <asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender3" runat="server" TargetControlID="pDelegateBody" CollapseControlID="pDelegateHeader" ExpandControlID="pDelegateHeader" Collapsed="true" TextLabelID="ShowDelegate" CollapsedText="Pick User..." ExpandedText="Close..." CollapsedSize="0"></asp:CollapsiblePanelExtender>
                </ContentTemplate>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td><asp:Label ID="DelegateNameLabel" runat="server" Text="Name:" CssClass="indentedText" /></td>
        <td><asp:Label ID="DelegateNameValueLabel" runat="server" CssClass="indentedText"  Visible="true"></asp:Label></td>
        <td><asp:Label ID="DelegateEmailLabel" runat="server" Text="Email:" CssClass="indentedText" /></td>
        <td><asp:Label ID="DelegateEmailValueLabel" runat="server" CssClass="indentedText" Visible="true"></asp:Label></td>
    </tr>
    <tr>
        <td><asp:Label ID="DelegatePhoneLabel" runat="server" Text="Phone:" CssClass="indentedText" /></td>
        <td><asp:Label ID="DelegatePhoneValueLabel" runat="server" CssClass="indentedText" Visible="true"></asp:Label></td>
        <td><asp:Label ID="DelegateVerifiedLabel" runat="server" Text="Last Verified Date:" CssClass="indentedText" /></td>
        <td><asp:Label ID="DelegateVerifiedValueLabel" runat="server" CssClass="indentedText" /></td>
    </tr>



protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string PassedDelegateID = string.Empty;
            string Mode = string.Empty;
            int delegateId = 0;

            if (Request.QueryString["Id"] != null)
            {
                PassedDelegateID = Request.QueryString["Id"].ToString();
            }
            else
            {
                PassedDelegateID = "0";
            }

            if (Request.QueryString["mode"] != null)
            {
                Mode = Request.QueryString["mode"].ToString();
            }
            else
            {
                Mode = "add";
            }

            if (Mode == "add")
            {
                pnlUdpateDelegateText.Text = UIConstants.ADDDELEGATETEXT.ToString();
            }
            else
            {
                pnlUdpateDelegateText.Text = UIConstants.UPDATEDELEGATETEXT.ToString();
                if (int.TryParse(PassedDelegateID, out delegateId))
                {
                    loadDelegateData(delegateId);
                }
            }
        }
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        TextBox txtSearchValue = (TextBox)PP.FindControl("txtSearchResults");
        string LanId = txtSearchValue.Text;

        User user = BusinessUtility.GetUser(LanId);

        DelegateNameValueLabel.Text = user.Name;
        DelegateEmailValueLabel.Text = user.Email;
        DelegatePhoneValueLabel.Text = user.Phone;
        DelegateVerifiedValueLabel.Text = DateTime.Now.ToShortDateString();


    }

Thanks, 谢谢,

Rhonda 朗达

Because the labels are outside the update panel, only the content inside the update panel is updated from an ajax post-back, that's the whole point of an update panel. 由于标签在更新面板之外,因此仅更新面板内部的内容是通过ajax回发来更新的,这就是更新面板的全部内容。

You will need to either move the labels inside the update panel's content area, or have another update panel for the labels and make it's update mode "always" 您将需要在更新面板的内容区域内移动标签,或者为标签添加另一个更新面板,并使它成为“始终”的更新模式。

Your lables are outside of the UpdatePanel . 您的标签在UpdatePanel之外。

Under the hood, ASP.Net performes a full postback, but only the part that pertains to your UpdatePanel is transfered back down to the client. 在幕后,ASP.Net执行完整的回发,但是只有与UpdatePanel相关的部分才被回传给客户端。 Some JavaScript then takes this bit of HTML and replaces the existing <div> element that is your UpdatePanel. 然后,某些JavaScript会使用这部分HTML,并替换现有的<div>元素(即UpdatePanel)。

Since your labels are outside of that <div> they never get updates. 由于您的标签不在该<div>之外,因此它们永远不会得到更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM