?
Solved

joining vb.net and javascript together for a confirm button

Posted on 2011-09-02
6
Medium Priority
?
258 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
5 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 83

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 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