这里是我在做什么。我创建两个按钮在一个标题行的内,我创造的。这些按钮是+页和网页。当页被击中我除寻呼及的所有数据转下页页的消失及多页的是存在的。

这才是我的问题 当我打+页面,我必须双postbacking因为一个排的我的数据就会消失。我会提供的编码如下。我能做些什么来解决这个吗?

Dim bttnrempag As New Button
    bttnrempag.ID = "bttnrempag"
    bttnrempag.Text = "      Paging"
    bttnrempag.CssClass = "bttnMinEG"
    bttnrempag.ValidationGroup = "alone"
    bttnrempag.Attributes.Add("onclick", "return Paging('1')")

    Dim bttnallowpag As New Button
    bttnallowpag.ID = "bttnallowpag"
    bttnallowpag.Text = "      Paging"
    bttnallowpag.ValidationGroup = "alone"
    bttnallowpag.CssClass = "bttnAddEG"
    bttnallowpag.Attributes.Add("onclick", "return Paging('0')")

---------------------如何按钮都加入------------------------------------------

    Dim row As New GridViewRow(-1, -1, DataControlRowType.Separator, DataControlRowState.Normal)
    row.Cells.Add(cell)
    cell.Controls.Add(bttnrempag) '36
    cell.Controls.Add(bttnallowpag)

----------------------------------------------------------------------------------------

function Paging(remove) {
    var gridView = $get('<%=Gridview1.ClientID %>');
    var txt2 = $get('<%=TextBox2.ClientID %>');
    if (remove == '1') {
        txt2.value = '1';
        __doPostBack('<%=UpdatePanel1.ClientID %>', '');
        return false;
    }
    else {
        txt2.value = '0';
        __doPostBack('<%=UpdatePanel1.ClientID %>', '');
        return false;
    }

编辑

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate >
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" 
            BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            DataSourceID="SqlDataSource1" Font-Names="Comic Sans MS" Font-Size="XX-Small"
            Caption = '<table border="" width="100%" cellpadding="3" cellspacing="0" bgcolor="#4A3C8C"><tr><td style = "font-size:X-large;font-family:Arial CE;color:White"><b>Ordering/Receiving Log</u></td></tr></table>' 
            Font-Bold="True" PageSize="15" >
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />

            <Columns>
                      Bound Data
            </Columns>
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <EmptyDataTemplate>
            <head>
                <meta http-equiv="refresh" content="5;URL=/Corporate_newpo/ReceivingLog.aspx?">
            </head>
                <script type="text/javascript" >
                    var count = 6;
                    var counter = setInterval("timer()", 1000); //1000 will  run it every 1 second

                    function timer() {
                        count = count - 1;
                        if (count <= 0) {
                            clearInterval(counter);
                            //counter ended, do something here
                            return;
                        }
                        $get("timer").innerHTML = "The Table will Reload in " + count + " secs";
                    }
                </script>
                <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large" 
                    ForeColor="#993333" Text="No Data was Found for the Selected Filter"></asp:Label><br /><br />
               <span id="timer" style="font-size:medium;color:blue"></span>
            </EmptyDataTemplate>
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <AlternatingRowStyle BackColor="#F7F7F7" />
            <PagerTemplate>
                <small 12px""="" style="font-size:xx-small; padding-right">Go To Page</small>
                <asp:DropDownList ID="ddlPageSelector" runat="server" AutoPostBack="true" 
                    Font-Size="XX-Small" Height="19px" Width="36px">
                </asp:DropDownList>
                <asp:ImageButton ID="btnFirst" runat="server" CommandArgument="First" 
                    CommandName="Page" SkinID="pagefirst" />
                <asp:ImageButton ID="btnPrevious" runat="server" CommandArgument="Prev" 
                    CommandName="Page" SkinID="pageprev" />
                <asp:ImageButton ID="btnNext" runat="server" CommandArgument="Next" 
                    CommandName="Page" SkinID="pagenext" />
                <asp:ImageButton ID="btnLast" runat="server" CommandArgument="Last" 
                    CommandName="Page" SkinID="pagelast" />
            </PagerTemplate>
            </asp:GridView>
        </ContentTemplate> 
    </asp:UpdatePanel>

所以你可以看到,当一个或另一个是打我设置一个文本框到一些值然后我做的一部分回到我的内其是在这Updatepanel.

有帮助吗?

解决方案

我已经找到了一个很好的解决方案,它的伟大工程。它并追加它自己的处理程序,但我想这可太固定的。

using System.Linq;

private void GridView_OnItemDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var buttons = e.Row.Cells.OfType<DataControlFieldCell>().SelectMany(item => item.Controls.OfType<ImageButton>());
        foreach (ImageButton imageButton in buttons)
        {
            var argument = imageButton.CommandName + "$" + imageButton.CommandArgument;
            imageButton.OnClientClick = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView, argument) + "; return false;";
        }
    }
}

其他提示

我怀疑这是因为你被称为“__doPostBack”的方法。该按钮的正常的默认点击行为将执行异步回发,则可能使其执行另一次。尝试删除它,看看它是如何去。

你可以尝试把在RowDataBound事件声明的按钮点击属性?

干杯。

试着改变你 <asp:ImageButtons> 将定期HTML <img> 标签。

我遇到这样的事情之前这是难以诊断和甚至更难以解释的。看看 在这里,在这里, 对于某些错误行为,可能会有帮助。如果你有 <img> 标签的空白src属性,然后在超级链接我提供可能说明问题。如果你没有任何空白的 <img> 标签,然后继续读我的工作的周围。

在我的特定情况下,它只是发生在某些服务器(在某些客户的地点)而不是其他的,所以我不能找到任何具体问题代码。我的解决方法是改变我的 <asp:ImageButtons> 定期的 <img> 标记与javascript击事件,这一功能以执行该回发,就像你寻呼()function.

由于某些原因,我们发现一个 <asp:ImageButton> 与客户的侧击事件的返回:确认('你确定?');将停止一回如果的确认()returns false,但是回返的假的你的方式做在你的寻呼()function后手叫__doPostBack不一致停止页张贴后的第二时间。

请在HTML看,因为它是在页面上呈现的:

每当它是本

<img src=""/>

双回送可能发生,一些浏览器...

此麻烦可以解决设置默认,空白,为每个按钮图像

<asp:ImageButton ImageUrl="~/Images/blank.gif"...>

总之,这个命令可以在输入Immediate Window如果你把内部Page_Load一个断点,并允许您的 indentify的引起回发

控制
Page.Request.Params["__EVENTTARGET"];

试试这个,(我不知道为什么你用javascript):

bttnrempag.onclick += bttnrempag_Click; 

protected void bttnrempag_Click(object sender, EventArgs e)
{
    //handle the removal of paging or whatever.
}

您必须对您的ImageButtons提供图像。否则,HTML渲染会产生<img src="">标签,当这个被渲染,就会造成回发。尝试。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top