Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

joining vb.net and javascript together for a confirm button

Posted on 2011-09-02
6
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

609 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