在ASP.Net是/否的MessageBox [英] Yes/No MessageBox in ASP.Net

查看:259
本文介绍了在ASP.Net是/否的MessageBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ASP.Net中使用JavaScript消息框带有是/否选项。该方案是,当我打电话上的一个按钮,它的做工精细的Client_click事件中的JavaScript函数。但是,当我打电话这从code的后面(C#),这将弹出的code完全执行后。下面是我想:

I want to use JavaScript Message-Box in ASP.Net with Yes/No option. The scenario is, when I am calling the JavaScript function on a Client_click event of a button, its working fine. But when I am calling this from code behind (C#), it pops-up after complete execution of the code. Here is what I am trying:

    protected void Message_Click(object sender, EventArgs e)
    {
        if (var == 1)
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "open", "Confirm();", true);
        }
        string confirmValue = Request.Form["confirm_value"];


        if (confirmValue == "Yes")
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
        }
        else
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Nothing has been selected')", true);
        }

    }

即使条件的 VAR == 1 是真的,我没有得到的字符串confirmValue 的更新值。
但是,如果我称之为的的OnClientClick ,它工作正常。通过几乎所有的网址,但没有运气去了呢。

Even if the condition var == 1 is true, I am not getting the updated value of string confirmValue. However if I call it on "OnClientClick", it works fine. Have gone through almost all the urls but no luck yet.

任何帮助将大大AP preciated。

Any help will be greatly appreciated.

推荐答案

您code将不等待服务器端的确认值。 <一href=\"https://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript%28v=vs.110%29.aspx\"相对=nofollow> Page.ClientScript.RegisterStartupScript 只是注册客户端脚本,那一刻方法的执行将完成。它将继续与code的下一行。这不是服务器来处理JavaScript的注册code的责任。所以,如果你想达到的 YES / NO 确认,然后等待服务器端与自定义$ C使用 AjaxModelPopupExtender $ C会给你你所需要的。
<一href=\"http://www.ajaxtutorials.com/asp-net/ajax-control-toolkit-modalpopupextender-tutorial-in-asp-net-c/\"相对=nofollow>在这里你可以得到关于如何使用ajaxmodel弹出扩展的更多信息。

Your code will do not wait for the confirmation value at the server side. Page.ClientScript.RegisterStartupScript will just register the client script and that moment that methods execution will be completed. And it will go on with the next line of the code. It is not the responsibility of the server to handle the registered javascript code. So if you want to achieve the Yes/NO confirmation and wait to server side use the AjaxModelPopupExtender with the custom code that will give you what you need. Here you can get more info on how to use the ajaxmodel pop up extender.

这篇关于在ASP.Net是/否的MessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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