本文介绍了在文本框更改文本的UpdatePanel之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UpdatePanel内的GridView(gridview的是显示在一个弹出)。在该网格选择按钮的点击,我想设置页面中的文本框的文本。但它不工作,如果我删除更新面板,然后它会工作。
请帮助。

这是在我的aspx code:

 < D​​IV>< ASP:文本框ID =TXT=服务器/>< / DIV>
     < ASP:的UpdatePanel ID =updLendersearch=服务器的UpdateMode =条件>
        <&触发器GT;
            < ASP:AsyncPostBackTrigger控件ID =btnLenderSearch事件名称=点击/>
        < /触发器>
        <&的ContentTemplate GT;
        < D​​IV ID =divLender=服务器级=white_content的风格=高度:450像素;顶部:20%;宽度:57%;>
        < ASP:标签ID =lblBenificiary=服务器文本=受益人/贷方:FONT-名称=Candara>< / ASP:标签>
        < ASP:文本框ID =txtBeneficiaryName风格=边界:1px的红色实心=服务器WIDTH =80px的CssClass =txtboxesFONT-名称=Candara>< / ASP:文本框>
        < ASP:的RequiredFieldValidator ID =reqBeneficiaryName=服务器的ErrorMessage =*前景色=红的ControlToValidate =txtBeneficiaryName的ValidationGroup =贷款人>< / ASP:&的RequiredFieldValidator GT;
        < ASP:标签ID =lblLenderState=服务器文本=状态:FONT-名称=Candara>< / ASP:标签>
          < ASP:DropDownList的ID =ddlLenderState=服务器的AutoPostBack =真正的风格=边界:1px的红色实心
                        AppendDataBoundItems =真的CssClass =drpdownOnSelectedIndexChanged =ddlLenderState_SelectedIndexChanged>
                    < / ASP:DropDownList的>
                    < ASP:的RequiredFieldValidator ID =reqLenderState=服务器的ErrorMessage =*前景色=红的ControlToValidate =ddlLenderState的ValidationGroup =贷款人>< / ASP:&的RequiredFieldValidator GT;
                    < ASP:标签ID =lblLenderCity=服务器文本=城市:FONT-名称=Candara>< / ASP:标签>
                      < ASP:DropDownList的ID =ddlLenderCity=服务器WIDTH =100像素的AutoPostBack =真
                        AppendDataBoundItems =真的CssClass =drpdownOnSelectedIndexChanged =ddlLenderCity_SelectedIndexChanged>
                    < / ASP:DropDownList的>
                    < ASP:标签ID =lblBeneficiaryZip=服务器文本=邮编:FONT-名称=Candara>< / ASP:标签>
                     < ASP:DropDownList的ID =ddlBeneficiaryZip=服务器AppendDataBoundItems =真WIDTH =100像素
                            的AutoPostBack =真的CssClass =drpdown>
                        < / ASP:DropDownList的>
                        < ASP:按钮的ID =btnBenefeciary的ValidationGroup =贷款人=服务器文本=搜索FONT-名称=Candara的CssClass =btnBenefeciary的OnClick =btnBenefeciary_Click/>
                        < BR>< BR>< BR>< BR>
                         < D​​IV>
    < ASP:GridView控件ID =grvLenderDetails的CssClass =GridViewStyleShowHeaderWhenEmpty =真OnRowCommand =grvLenderDetails_RowCommand=服务器的AutoGenerateColumns =false的AutoGenerateSelectButton =真>
    <柱体和GT;
    .. .. ..
    < /专栏>
    < EmptyDataTemplate>
            无记录可显示
        < / EmptyDataTemplate>
    < / ASP:GridView的>
    < / DIV>
        < / DIV>
        < D​​IV ID =fadeLender级=black_overlay=服务器>
            < ASP:ImageButton的ID =imgLenderClose的ImageUrl =../图像/ closepnlbtn.png=服务器
                ALIGN =正确的风格=缘右:140px;的margin-top:78px; BORDER:0像素的OnClick =imgLenderClose_Click/>
        < / DIV>
    < /&的ContentTemplate GT;
< / ASP:的UpdatePanel>


解决方案

我假设文本框是另一个的UpdatePanel 。使得它的UpdateMode 条件,它允许调用它的编程更新方法。

 保护无效ddlLenderState_SelectedIndexChanged(对象发件人,GridViewSelectEventArgs E)
{
    TxtInfo.Text =你好,我是在GridView的到来。
    UpdInfo.Update();
}

另一个形式给出将添加一个 AsyncPostBackTrigger 的UpdatePanel 控件ID = grvLenderDetails 事件名称=的SelectedIndexChanged

修改:如果不是在的UpdatePanel 更改。下面举例说明:

 < ASP:的UpdatePanel =服务器ID =UpdInfo的UpdateMode =条件>
   <&的ContentTemplate GT;
       < ASP:文本框ID =TxtInfo=服务器/>
   < /&的ContentTemplate GT;
< / ASP:的UpdatePanel>

下面的触发方式,不需要调用更新()从手动codebehind:

 < ASP:的UpdatePanel =服务器ID =UpdInfo的UpdateMode =条件>
   <&的ContentTemplate GT;
       < ASP:文本框ID =TxtInfo=服务器/>
   < /&的ContentTemplate GT;
   <&触发器GT;
       < ASP:AsyncPostBackTrigger控件ID =grvLenderDetails事件名称=的SelectedIndexChanged/>
   < /触发器>
< / ASP:的UpdatePanel>

I have a gridview inside an UpdatePanel ( gridview is showing in a popup). On click of select button in that grid I am trying to set a textbox text in the page. But its not working ,if I remove the update panel then it will work.Please help.

This is my code in 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>
解决方案

I assume that the TextBox is in another UpdatePanel. Make it's UpdateMode Conditional which allows to call it's Update method programmatically.

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

Another aproach would be to add an AsyncPostBackTrigger to the outer UpdatePanel with ControlID=grvLenderDetails and EventName=SelectedIndexChanged.

Edit: If it's not in an UpdatePanel change it. Here are examples:

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

Here the trigger approach that does not require to call Update() from codebehind manually:

<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>

这篇关于在文本框更改文本的UpdatePanel之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:53