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

Solution 1


Try this:

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

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
              // 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:


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


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

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