c# - 停止双重回发

标签 c# asp.net javascript vb.net updatepanel

这是我正在做的。我在我创建的 gridview 的标题行中创建了两个按钮。按钮是 +page 和 -page。当 -page 被点击时,我删除了分页,所有数据都沿着页面向下移动,-page 消失,+page 在那里。

我的问题来了 当我点击 +page 时,我必须进行双重回发,因为我的一行数据消失了。我将在下面提供代码。我该怎么做才能解决这个问题??

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>

正如您所看到的,当一个或另一个被点击时,我将一个文本框设置为某个值,然后我对我的 Gridview 进行部分回发,它位于该 Updatepanel 中。

最佳答案

我怀疑这是因为您调用了“__doPostBack”方法。按钮的正常默认点击行为将执行异步回发,您可能让它在其他时间执行。尝试将其删除,看看效果如何。

关于c# - 停止双重回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1439312/

相关文章:

javascript - 同步调用函数并返回值

c# - 以新格式打开图像C#

asp.net - 为什么有 2 个 web.config 文件

asp.net - 有没有办法在 WinForm/Console/VSTest 应用程序中使用 XmlSiteMapProvider?

asp.net - 多个 UI 的接口(interface) Controller (ViewModel)

javascript - 使用AJAX接收 "Uncaught SyntaxError: Unexpected token ("

Javascript正则表达式允许负双值?

c# - 为什么我收到错误 Cannot await 'void' ?

c# - 获取token时如何解析 "possible System.NullReferenceException"

c# - 有没有办法为 UserPrincipal.FindByIdentity() 启用推荐追踪?