5

我在 UpdatePanel 中有一个 gridview(gridview 显示在弹出窗口中)。单击该网格中的选择按钮时,我正在尝试在页面中设置文本框文本。但它不起作用;如果我删除更新面板,那么它将起作用。

这是我在 aspx 中的代码:

<div><asp:TextBox ID="txt" runat="server /></div>
     <asp:UpdatePanel ID="updLendersearch" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnLenderSearch" EventName="Click" />
        </Triggers>
        <ContentTemplate>
        <div id="divLender" runat="server" class="white_content" style="height: 450px;top: 20%;width: 57%;">
        <asp:Label ID="lblBenificiary" runat="server" Text="Beneficiary/Lender :" Font-Names="Candara" ></asp:Label>
        <asp:TextBox ID="txtBeneficiaryName" Style="border: 1px solid red" runat="server" Width="80px" CssClass="txtboxes" Font-Names="Candara" ></asp:TextBox>
        <asp:RequiredFieldValidator ID="reqBeneficiaryName" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="txtBeneficiaryName" ValidationGroup="lender"></asp:RequiredFieldValidator>
        <asp:Label ID="lblLenderState" runat="server" Text="State :" Font-Names="Candara" ></asp:Label>
          <asp:DropDownList ID="ddlLenderState" runat="server" AutoPostBack="true" Style="border: 1px solid red" 
                        AppendDataBoundItems="true" CssClass="drpdown" OnSelectedIndexChanged="ddlLenderState_SelectedIndexChanged">
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="reqLenderState" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="ddlLenderState" ValidationGroup="lender"></asp:RequiredFieldValidator>
                    <asp:Label ID="lblLenderCity" runat="server" Text="City :" Font-Names="Candara" ></asp:Label>
                      <asp:DropDownList ID="ddlLenderCity" runat="server" Width="100px" AutoPostBack="true"
                        AppendDataBoundItems="true" CssClass="drpdown" OnSelectedIndexChanged="ddlLenderCity_SelectedIndexChanged">
                    </asp:DropDownList>
                    <asp:Label ID="lblBeneficiaryZip" runat="server" Text="Zip :" Font-Names="Candara" ></asp:Label>
                     <asp:DropDownList ID="ddlBeneficiaryZip" runat="server" AppendDataBoundItems="true" Width="100px"
                            AutoPostBack="true" CssClass="drpdown">
                        </asp:DropDownList>
                        <asp:Button ID="btnBenefeciary" ValidationGroup="lender" runat="server" Text="Search" Font-Names="Candara" CssClass="btnBenefeciary" OnClick="btnBenefeciary_Click"/>
                        <br><br><br><br>
                         <div>
    <asp:GridView ID="grvLenderDetails" CssClass="GridViewStyle" ShowHeaderWhenEmpty="true" OnRowCommand="grvLenderDetails_RowCommand" runat="server" AutoGenerateColumns="false" AutoGenerateSelectButton="true">
    <Columns>
    .. .. ..
    </Columns>
    <EmptyDataTemplate>
            No Records To Display
        </EmptyDataTemplate>
    </asp:GridView>
    </div>
        </div>
        <div id="fadeLender" class="black_overlay" runat="server">
            <asp:ImageButton ID="imgLenderClose" ImageUrl="../Images/closepnlbtn.png" runat="server"
                align="right" Style="margin-right: 140px; margin-top: 78px; border: 0px" OnClick="imgLenderClose_Click" />
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
4

1 回答 1

10

如果TextBox在另一个UpdatePanel. 使其 UpdateModeConditional允许您以Update编程方式调用其方法。

protected void ddlLenderState_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
{
    TxtInfo.Text = "Hello, i'm coming from the GridView.";
    UpdInfo.Update();
}

另一种方法是用andAsyncPostBackTrigger向外部添加一个。UpdatePanelControlID=grvLenderDetailsEventName=SelectedIndexChanged

如果它不在 中UpdatePanel,那么您需要更改它。以下是示例:

<asp:UpdatePanel runat="server" ID="UpdInfo" UpdateMode="Conditional">
   <ContentTemplate>
       <asp:TextBox ID="TxtInfo" runat="server />
   </ContentTemplate>
</asp:UpdatePanel>

这是不需要您Update()手动从代码隐藏调用的触发方法:

<asp:UpdatePanel runat="server" ID="UpdInfo" UpdateMode="Conditional">
   <ContentTemplate>
       <asp:TextBox ID="TxtInfo" runat="server />
   </ContentTemplate>
   <Triggers>
       <asp:AsyncPostBackTrigger ControlID="grvLenderDetails" EventName="SelectedIndexChanged" />
   </Triggers>
</asp:UpdatePanel>

否则,您将需要使用某种 JS 技巧,例如:

ScriptManager.RegisterStartupScript(this, GetType(), "ChangeTextBoxText", "<script type='text/javascript'>$('#"+txt.ClientId+"').val('Hello, i'm from the GridView');</script>", false);
于 2013-09-20T07:42:33.380 回答