Solved

joining vb.net and javascript together for a confirm button

Posted on 2011-09-02
6
248 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 46
Disable extension 8 38
VB: Convert 2 dates to specific format 24 48
Help with converting xml file to excel using VB.NET 3 20
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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