Click here to Skip to main content
16,018,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can I get value of confirm msgbox(javascript) in code behind(aspx.cs)page??
Pls.Help
Posted

Hi,

Try this:

In .aspx file
ASP
<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>

In .aspx.cs file:
C#
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
          }
      }
Hope this helps.
 
Share this answer
 
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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900