0

I have a button on my ASP.NET webforms application when i click it I get a yes no message box, behind the scenes i.e., the button click event I have some code which deletes data from the database. I would like to delete code to only run when the use selects yes on the message box.

I have got the message box working using the script below

 <script type="text/Javascript" language ="javascript" >
function confirm_meth()
{
  if( confirm("Do you want to continue!Click 'OK'")==true)
  {
        document.writeln ("<b>You had click on 'YES' Button</b>");
   }
  else
  {
       document.writeln ("<b>You had clic on 'CANCEL' Button</b>");
  }
}
</script>

<td class="auto-style5">

                    <asp:Button ID="DeleteJobsbtn" runat="server" Text="Delete Jobs"
                        OnClientClick =" return confirm_meth()"/>


                </td>

How do i send this to the code behind to the click event?

I am using ASP.net Webforms VB.Net

Abe
  • 1,879
  • 2
  • 24
  • 39
  • [javascript return true or return false when and how to use it?](https://stackoverflow.com/questions/19166296/javascript-return-true-or-return-false-when-and-how-to-use-it) ? – Flakes Aug 05 '18 at 04:35

1 Answers1

0

You need yo add a asp net hidden field and through javascript assign the value you want to it. You could add an on change event to your hidden field and in that event you can query the hidden field from your code behind.

<script runat="server">
  void ValueHiddenField_ValueChanged (Object sender, EventArgs e)
  {

    // Display the value of the HiddenField control.
    Message.Text = "The value of the HiddenField control is " + ValueHiddenField.Value + ".";

  }
</script>

HiddenField Example

        <h3> Example</h3>

        Please enter a value and click the submit button.<br/>

        <asp:Textbox id="ValueTextBox"
          runat="server"/>

        <br/>  

        <input type="submit" name="SubmitButton"
         value="Submit"
         onclick="PageLoad()" />

        <br/>

        <asp:label id="Message" runat="server"/>    

        <asp:hiddenfield id="ValueHiddenField"
          onvaluechanged="ValueHiddenField_ValueChanged"
          value="" 
          runat="server"/>

    </form>
</body>

Dalorzo
  • 19,834
  • 7
  • 55
  • 102