Solved

joining vb.net and javascript together for a confirm button

Posted on 2011-09-02
6
246 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:runnerjp2005
6 Comments
 
LVL 19

Expert Comment

by:Bardobrave
ID: 36472952
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.
0
 

Author Comment

by:runnerjp2005
ID: 36473444
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
0
 
LVL 19

Expert Comment

by:Bardobrave
ID: 36473713
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.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36478286
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
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 36492307
>i have added a dynamic button via a calander...
Is it an ASP.NET button control? Use the onclick to register the server side event handler and use the javascript in OnClientClick and with return statement.

This example is for LinkButton but is similar

http://www.asp.net/data-access/tutorials/adding-client-side-confirmation-when-deleting-cs
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now