English 中文(简体)
在小组内部出现倒退后,复职状态不会持续下去。
原标题:State of repeater is not persisted after postback when inside a panel

我有以下编码结构:

        <asp:Panel ID="Panel1" runat="server" Title="TestPanel" Visible="true">
          <asp:GridView ID="grd1" runat="server" AutoGenerateColumns="true">        
          </asp:GridView>
          <myControl:RepeaterUserControl ID="rpt"></myControl:RepeaterUserControl>
        </asp:Panel>

The panel is used to control visibilty (currently set true for all time). The control RepeaterUserControl is a user control which contains a asp repeater with two buttons named Ok and Cancel (all initially set display:none). All this content of user control is shown on page as modal popup (using modal popup extender) on click of a Invoke button which is also a part of the user control.

<div id="div1" runat="server">
    <ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="divDialog"
        TargetControlID="btnDummyInvoker" CancelControlID="imbClose" PopupDragHandleControlID="divDialogTitle"
        BackgroundCssClass="modalBackground">
    </ajax:ModalPopupExtender>
    <div style="height: 4px;">
    </div>
    <asp:Button ID="btnInvoke" runat="server" OnClick="btnInvoke_Click" Text="Invoke"
        Width="90px" />
    <div style="display: none; position: absolute;">
        <asp:Button ID="Button2" runat="server" />
    </div>
    <div id="div2" runat="server" style="display: none;">
        <asp:Repeater ID="rptList" runat="server">
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label ID="lblName" runat="server" Text= <%# Eval("DisplayText").ToString() %> ></asp:Label>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
        <asp:Button ID="btnOk" runat="server" OnClick="btnOk_Click" />
        <asp:Button ID="btnCancel" runat="server" />
    </div>
</div>

因此,用户在电网以下的网页上看到一个纽吨(Invoke),其中显示在电动波中重复控制以及Ok/Cancel纽吨。 复读者被分配到一个数据来源,其中列有项目清单,用户作改动,在烟 click点点点上,从背后的代码(在波茨克事件)一接重复器作为耳机。 项目。 有更多的行动要做。

Now the problem. If the user control is outside the panel it perfectly returns me the correct count of items, but if the userControl in inside the panel (as shown in code) the count returned on click of ok button is 0 after postback. why is the repeater losing its state in this case ?

<>Update>: 如果能够帮助解决问题,则从表面上添加法典。

//This is from the user control code
 protected void btnInvoke_Click(object sender, EventArgs e)
        {   
          rptList.DataSource = listToBeBoundToRepeater;
          rptList.DataBind();
          modalPopupExtender.Show();             
        }

//This is from the user control code
 protected void btnOk_Click(object sender, EventArgs e)
        {

            for (int itemIndex = 0; itemIndex < rptList.Items.Count; itemIndex++)
            {
               // business logiv
            }

        }

rptList.Items.Count,在我所描述的案件出现倒退之后,为我开了。

update2 : Here is the weird solution I got, I enclosed the grid and repeater with a tag and set the runat property to server to make it a server control. Now its persisting the values of the repeater after postback properly. Strange, but working now.

最佳回答

这里是我所走的令人厌恶的解决办法,我把电网和重复器附在一个标签上,并将跑道财产交给服务器,使之成为服务器控制。 如今,它一直坚持重复者在适当退后的价值。 时间安排,但现在工作。

问题回答

<asp:UpdatePanel ID=“UpdatePanel1”prat=“server”>,下定义AsyncPostback Trigger as btnInvoke

Edit: Removed previous answer.
I tried simulating your problem as much as possible in using a main panel containing a usercontrol which contains a repeater that is shown with the ajaxcontroltoolkit.
Alas my repeater item count is always correct though.
Container page :

<%@ Register TagPrefix="a" TagName="test" Src="cc.ascx" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server" />   
    <asp:Panel ID="Panel1" runat="server" Title="TestPanel" Visible="true">
        <a:test runat="server" ID="test"></a:test>
    </asp:Panel>
</asp:Content>

用户控制 cc aspx :

<%@ Register TagPrefix="ajax" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit, Version=4.1.60501.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>

<div id="div1" runat="server">
    <ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="divDialog"
        TargetControlID="btnDummyInvoker"
        BackgroundCssClass="modalBackground">
    </ajax:ModalPopupExtender>
    <asp:Button runat="server" style="display:none" ID="btnDummyInvoker"/>
    <div style="height: 4px;">
    </div>
    <asp:Button ID="btnInvoke" runat="server" OnClick="btnInvoke_Click" Text="Invoke" Width="90px" />
    <div style="display: none; position: absolute;">
        <asp:Button ID="Button2" runat="server" />
    </div>
    <div id="divDialog" runat="server" style="display: none;">
        <asp:Repeater ID="rptList" runat="server">
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label ID="lblName" runat="server" Text= <%# Eval("DisplayText").ToString() %> ></asp:Label>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
        <asp:Button ID="btnOk" runat="server" OnClick="btnOk_Click" />
        <asp:Button ID="btnCancel" runat="server" />
    </div>
    <asp:TextBox runat="server" ID="result"></asp:TextBox>
</div>

用户控制代码如下:

public partial class cc : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnInvoke_Click(object sender, EventArgs e)
        {
            var list = new List<Data>();
            list.Add(new Data { DisplayText = "one" });
            list.Add(new Data { DisplayText = "two" });
            rptList.DataSource = list;
            rptList.DataBind();
            ModalPopupExtender1.Show();
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            var count = rptList.Items.Count;
            result.Text = count.ToString();
        }
    }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签