Calling Javascript from a vb.net Method - Confirm()

J

J Sahoo

I have an asp button on my form. If user clicks the button then my
Javascript code Confirm pops up with "Ok" & "Cancel" button. If the
user clicks "Ok" from my pop-up then I do my vbMethod doApproveIt().
This works great if the Javascript returns true and I show the message
that the record is approved.

But if the user does not select "OK", chooses "cancel" button then
doApproveIt() method never executes. What I want is, how can I get the
RESPONSE of the user (either true or false) in a variable and
accordingly I want to show message to the user. Now I can not show any
message if the user chooses "cancel", since my method is not executed.


If I remove the return from the Confirm() method, doApproveIt() vb
method executes whteher user presses "OK" or "Cancel", But I need to
check the response in my vb method (what the user pressed), What do I
check to see the response, please provide me some sample code if
possible.

Thank you.

Sahoo J

Here is the code I have in my program:


<asp:button id="btnApprove" onclick="doApproveIt" runat="server"
Height="56px" Width="172px"
ForeColor="#C00000" Font-Size="Large" Font-Bold="True"
Text="Approve"></asp:button>


// The following code is in my pageLoad event.

btnApprove.Attributes("OnClick") = "return confirm('Are you sure, you
want to Approve this Record?');"

// VB Code
Sub doApproveIt(ByVal Source As Object, ByVal E As EventArgs) ' this
executes if value is TRUE , user confirms delete
createApproval("1") ' Approve was selected
' what do I check to see if the user has pressed CANCEL button, I need
to show msg
End Sub
 
B

Bruno Sirianni

I simple way to store the response on client and have it on server is to use
a simple <input type=hidden id=response name=response> tag.

On client you can access to the value of this tag with
document.all['response'].value and set it.
On server (VB.NET) you can use Request.Form("response") for retrieve the
response value!

I hope this can help you!

Brun
 
J

J Sahoo

Thank you Mr. Bruno. It works great with the hidden field.

Sahoo J


Bruno Sirianni said:
I simple way to store the response on client and have it on server is to use
a simple <input type=hidden id=response name=response> tag.

On client you can access to the value of this tag with
document.all['response'].value and set it.
On server (VB.NET) you can use Request.Form("response") for retrieve the
response value!

I hope this can help you!

Brun


J Sahoo said:
I have an asp button on my form. If user clicks the button then my
Javascript code Confirm pops up with "Ok" & "Cancel" button. If the
user clicks "Ok" from my pop-up then I do my vbMethod doApproveIt().
This works great if the Javascript returns true and I show the message
that the record is approved.

But if the user does not select "OK", chooses "cancel" button then
doApproveIt() method never executes. What I want is, how can I get the
RESPONSE of the user (either true or false) in a variable and
accordingly I want to show message to the user. Now I can not show any
message if the user chooses "cancel", since my method is not executed.


If I remove the return from the Confirm() method, doApproveIt() vb
method executes whteher user presses "OK" or "Cancel", But I need to
check the response in my vb method (what the user pressed), What do I
check to see the response, please provide me some sample code if
possible.

Thank you.

Sahoo J

Here is the code I have in my program:


<asp:button id="btnApprove" onclick="doApproveIt" runat="server"
Height="56px" Width="172px"
ForeColor="#C00000" Font-Size="Large" Font-Bold="True"
Text="Approve"></asp:button>


// The following code is in my pageLoad event.

btnApprove.Attributes("OnClick") = "return confirm('Are you sure, you
want to Approve this Record?');"

// VB Code
Sub doApproveIt(ByVal Source As Object, ByVal E As EventArgs) ' this
executes if value is TRUE , user confirms delete
createApproval("1") ' Approve was selected
' what do I check to see if the user has pressed CANCEL button, I need
to show msg
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top