Click here to Skip to main content
14,575,143 members
Rate this:
Please Sign up or sign in to vote.
See more:
how can I get value of confirm msgbox(javascript) in code behind(aspx.cs)page??
Pls.Help
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

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>

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
          }
      }
Hope this helps.
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100