如何prevent回发ASP的按钮,同时显示使用JQuery弹出 [英] How to prevent postback on asp button while displaying a popup using JQuery

查看:189
本文介绍了如何prevent回发ASP的按钮,同时显示使用JQuery弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的的ItemTemplate 在我的GridView的:

I have the following ItemTemplate in my GridView:

<ItemTemplate>
    <asp:Button UseSubmitBehavior="false" runat="server" ID="btnShow" CssClass="btnSearch" Text="View All" CommandName="ViewAll" OnClientClick="myfunction(); return false;" OnCommand="btnShow_Command" CommandArgument='<%#((GridViewRow)Container).RowIndex%>' />
</ItemTemplate>

对于的ItemTemplate 我有,当使用以下的JQuery点击打开一个弹出窗口中的按钮:

For the ItemTemplate I have a button which opens a popup window when clicked by using the following JQuery:

$(document).ready(function () {
    $(".btnSearch").click(function (e) {
        e.preventDefault();
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
    });
});

function myfunction() {
}

我的命令 code-背后:

protected void btnShow_Command(object sender, CommandEventArgs e)
        {
            int index = 0;

            if (e.CommandName == "ViewAll")
            {
                index = Convert.ToInt32(e.CommandArgument);

                DataTable cacheTable = HttpContext.Current.Cache["ResultsTable"] as DataTable;

                string column = cacheTable.Rows[index].Field<string>("Guideline");
                string test = BookingResults.Rows[index].Cells[7].Text;
                string html = HttpUtility.HtmlDecode(column);

                ResultsDiv.InnerHtml = html;
                //tbGL.Text = html;
                //upData.Update();
                //MessageBox.Show(index.ToString());
            }
        }

我添加了的OnClientClick =MyFunction的();返回false;,因为它在做每一次我点击了一个回发。如果我有多个行,它只我第一次点击,但任何时间后,在单击另一个或同一按钮时不显示弹出式窗口。

I added the OnClientClick="myfunction(); return false;" because it was doing a postback each time I clicked. If I have multiple rows, it only works the first time I click but any time after, the popup is not displayed when another or the same button is clicked.

我怎么这么不管解决这个问题单击显示的弹出哪个按钮而不做回发?

How do I resolve it so no matter which button is clicked the popup is displayed without doing a postback?

推荐答案

其实你还没有露面的方法的实施 myfunction的(),以防在 myfunction的()方式有任何语法错误,那么在的OnClientClick 事件将被作废,并会后回/表单提交到服务器。

Actually you have not showed up the implementation of your method myfunction(), in case the myfunction() method have any syntactical error then the OnClientClick event will be void and it will post-back/submit the form to the server.

尝试删除从通话的的OnClientClick 并只实现你的逻辑在jQuery的在单击事件使用的类选择如下:

Try to remove the call from OnClientClick and just implement your logic at jquery on click event by using class selector as follows

$(document).ready(function () {
        $(".btnSearch").click(function (e) {
            e.preventDefault();
            alert($(this).val() + " Clicked"); // you can put your method mymethod() here 
            // you can put youe popup logic here

            return false; 

        });
    });

您还可以看到这个例子爵士小提琴

You can also see this example of js fiddle

这篇关于如何prevent回发ASP的按钮,同时显示使用JQuery弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆