需要执行JavaScript确认为C#的消息框 [英] Need to executeJavaScript confirm as Message box of c#

查看:141
本文介绍了需要执行JavaScript确认为C#的消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我.

我有以下代码.

必须执行Java脚本代码并将其发送回,以便我可以在下一行执行操作.

问题是单击事件执行后,我得到了确认框.

任何人都可以为我提供解决方案吗?

在此先感谢

Java脚本:

Please Help me.

I have the following code.

The java script code has to be executed and send back the result so that i could execute my operation next line.

The problem is i get the confirm box after the click event gets executed.

Can any one provide me solution?

Thanks in advance

Java Script:

<script type="text/javascript">
      function GetResult()
      {
       var ans = confirm('Are you the people from Planet Earth?');
        if(ans)
        document.getElementById("HiddenField1").value="YES";
        alert(ans)
       }
    </script>




c#:




c#:

protected void Button2_Click1(object sender, EventArgs e)
      {
          bool india = true;
          if (india)
          {
              india = false;
          }
          if(!india)
          {
              ClientScript.RegisterStartupScript(GetType(), "text/javascript", "javascript:GetResult();", true);
              if (HiddenField1.Value == "YES")
              {
                // logic
              }
          }
      }

推荐答案

您必须在设计如下所示的按钮的OnClientClick事件中调用javascript.
You have to call the javascript in the button''s OnClientClick event in design like below.
<asp:Button ID="btn" runat="server" OnClientClick="GetResult()"/>


问题是单击事件被执行后,我得到了确认框.
那是因为您正在服务器端的click事件上调用Javascript函数.删除该行,并在您的asp:Button标记上,添加OnClientClick ,然后将其指向您的Javascript函数.
The problem is i get the confirm box after the click event gets executed.
That is because you are calling the Javascript function on the server side click event. Remove that line and on your asp:Button tag, add OnClientClick and then point it to your Javascript function.


这篇关于需要执行JavaScript确认为C#的消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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