Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

joining vb.net and javascript together for a confirm button

How would i correctly join the javascript and vb.net code together?
  Dim strMessage As String = "Do you want to remove your holiday booked on this day?"
            Page.RegisterStartupScript("script1", "<script language='javascript'>" & _
                   "confirm('" & strMessage & "');</" & "script>")

          if (confirm('"strMessage"')) {

                dateallreadybooked.deleteit(result.Split("|")(1)), "Jarratt")

                }

Open in new window

Avatar of Bardobrave
Bardobrave
Flag of Spain image

I think it would be better if you explain us what are you trying to do with this code.

I see that you're trying to somewhat associate a script to the page depending on a message. But I cannot understand why do you need to use that code on server side.
Avatar of Member_2_5230414
Member_2_5230414

ASKER

i have added a dynamic button via a calander...

if the user clicks the ok button on java i want to exicute some code that will delete the date from the calander which i have stored in the db.

I all want to do is if user clicks ok... run code
Ok, as I understand you, what you are seeking is to execute a piece of server code firing it from a client event on javascript.

AJAX is the ideal approach for such a situation.

What you must do is to manage the click event on javascript and from there make an AJAX call to your server code.

Here you have two links to understand and give your first steps with AJAX calls:
http://msdn.microsoft.com/en-us/library/aa479042.aspx
http://www.w3schools.com/ajax/default.asp

And, if you use jQuery, you should know that it includes a very powerful, easy and intuitive method to make ajax calls:
http://api.jquery.com/jQuery.ajax/

If you don't use jQuery spare some time giving it a chance, you'll probably discover that's a wonderful tool.
Avatar of leakim971
ok, create a hidden field (.net control or not), for example :                                                                                        
<asp:HiddenField ID="HiddenField1" runat="server" />

Open in new window

Before leaving the page (postback) we update the value of this hidden field with the following javascript (put it in the head secion :
<script language="javascript" type="text/javascript">
    window.onbeforeunload = function () {
        if (confirm("Do you want to remove your holiday booked on this day?")) {
            document.getElementById("<%= HiddenField1.ClientID %>").value = "YES";
        }
        else {
            document.getElementById("<%= HiddenField1.ClientID %>").value = "NO";
        };
    }
</script>
so test the value of the HiddenFIeld on the server side to delete or not
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial