在(aspx.cs)页面后面的代码中确认msgbox(javascript)的值? [英] value of confirm msgbox(javascript) in code behind(aspx.cs)page?

查看:64
本文介绍了在(aspx.cs)页面后面的代码中确认msgbox(javascript)的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在后面的代码(aspx.cs)页面中获取确认msgbox(javascript)的值?

Pls.Help

how can I get value of confirm msgbox(javascript) in code behind(aspx.cs)page??
Pls.Help

推荐答案





试试这个:



在.aspx文件中

Hi,

Try this:

In .aspx file
<form runat="server">
       <asp:button id="btn1" runat="server" onclientclick="confirming();" onclick="btn1_Click" text="Submit" xmlns:asp="#unknown" />
 </form>
   <script type="text/javascript">
       function confirming() {
           document.getElementById('<%=confirmValue.ClientID%>').value = confirm('Yes or no?');
       }
   </script>



在.aspx.cs文件中:


In .aspx.cs file:

protected void btn1_Click(object sender, EventArgs e)
      {
          string confirmValueStr = confirmValue.Value;
          bool confirmValueBool;
          if (bool.TryParse(confirmValueStr, out confirmValueBool)
          {
              // now, confirmValueBool is the value of the confirm function
          }
          else
          {
              // can't convert confirmValueStr to confirmValueBool
          }
      }

希望这会有所帮助。


之前我做的是创建一个< asp:hiddenfield xmlns:asp =#unknown/>然后在我的javascript中我将HiddenField的值设置为变量的值with document.getElementById( HiddenFieldID )。value = variable。

所以在你的情况下它会是这样的:



HTML:



< ; asp:hiddenfield id =Msgrunat =server/>



Javascript:



document.getElementById(Msg)。value = msgbox.value(不确定获取msgbox的值)



然后在后面的代码中你可以只需参考Msg.Value



希望这有帮助
What I have done before is create a <asp:hiddenfield xmlns:asp="#unknown" /> then in my javascript I set the HiddenField's value to that of the variable with document.getElementById("HiddenFieldID").value = variable.
So in your case it would be something like:

HTML:

<asp:hiddenfield id="Msg" runat="server"/>

Javascript:

document.getElementById("Msg").value = msgbox.value(not sure about getting the value of the msgbox)

and then in the code behind you could just reference the Msg.Value

Hope this helps


这篇关于在(aspx.cs)页面后面的代码中确认msgbox(javascript)的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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