Script and Code

nate

Freshman
Joined
Dec 2, 2006
Messages
36
OK, this might be a dumb one but I am a little confused I am newer to the asp side of things so sorry if it is a stupid one. I am using VB.Net to make my aspx pages. I am using java script to show message boxes. I want to make a yes/no message box and make something happen on the code side of things. I used to use something like

dim result
result=msgbox("Do You want this feature", vbyesno)
if result=vbyes then
blah blah blah

but how do I comunicate the java script alert result to trigger some code in my .vb file? Or can I use some sort of message box? Thanks.
 
OK I am using this below:

Code:
Public Function ConfirmFood()
Dim Alert As New Label
   Alert.Text = "<script language='vbscript'>" & _
   vbNewLine & "Confirm(" & """" & "Do You want some food?" & """" & ")" & _
   vbNewLine & "return true; </script>"
   Page.Controls.Add(Alert)
End Function

How can I return the value? If I do this:

Code:
Public Function ConfirmFood()
Dim Alert As New Label
   Alert.Text = "<script language='vbscript'>" & _
   vbNewLine & "Confirm(" & """" & "Do You want some food?" & """" & ")" & _
   vbNewLine & "return true; </script>"
   Page.Controls.Add(Alert)
   Return Alert
End Function

It errors out because Alert is a label. Please Help. Thanks
 
Hi Nate

Here is what I do for the confirm dialog/messagebox using javascript:

In my page load method I have the following line of code:
Code:
btnSend.Attributes.Add("onclick", "if(confirm('Are you sure you want to do this?')){}else{return false}")

I then have my normal btnSend_Click method that handles the button click.

Just make sure that your btnSend is an asp.net button.

When you click the button, you will get a javascript dialog asking you the above question, you will be give to two options, Ok or Cancel. I still haven't figured out how to changed this to Yes and No. You would probabily need to create your own javascript button.

Now if you click on the OK button, the javascript will allow you to proceed to the btnSend_Click method. If you click on the Cancel button, then the javascript will simply act as if you never click the button.

Hope this helps.

Mike55.
 
Back
Top