VB HiddenField loses value after setting value in Javascript [jQuery dialog]

47 Views Asked by At

I am currently struggling with the implementation of the jQuery Dialog in an Visual Basic Web Application. In the following code there is a Button, that forces a jQuery dialog to open. I just want to access the result of the dialog (Yes/No) in the Visual Basic Code.

This is my VB-Code:

<input id="hfSandbox" type="hidden" runat="server"  />

<asp:Button runat="server" ID="btnSandbox"  OnClick="btnSandbox_Click" Text="Button" />

<div id="dialog" >Everything OK?</div>

With following Javascipt code i want to set the value of a hidden field to true or false, depending on which response the user chooses. With an alert I check, if the value is set correctly (if user chooses "Yes").

    $(function () {

        $("#dialog").dialog({
            title: "Bestätigung",
            buttons: {
                Yes: function () {

                     document.getElementById("<%=hfSandbox.ClientID%>").Value = "True"
                     alert(document.getElementById("<%=hfSandbox.ClientID%>").Value)

                    $("[id*=btnSandbox]").click();

                },
                No: function () {

                    $(this).dialog('close');
                }
            }
        });
    });

After that, I trigger the click event in VB. In the VB function I want to access the value of the hidden field.

Protected Sub btnSandbox_Click(sender As Object, e As EventArgs)

    MsgBox(hfSandbox.Value)

End Sub

This is where I fail. The message box has no content. I tried several things I read in other communities- but no luck. I hope you can help me!

Cheers

1

There are 1 best solutions below

1
xxx On

Your function is not self-executing. Why don't you do everything in VB.net like:

If MsgBox("message or question", MsgBoxStyle.YesNo,"Tittle") = MsgBoxResult.Yes Then 'Your code here

End If