Confirmation Message Box (return Value from Javascript to ASP.NET program ). Please help !!!

B

bienwell

Hi all,

I just have a question about using confirmation message box in ASP.NET
program. It's an emergency !!!

In my program, I have an ASP button runat='server' that calls a Sub
Function when users click this button. In this Sub Function, I have some
conditions:

If Cond_A Then
Display Confirmation box which has Yes and No buttton (Call
Javascript to display confirmation message box)
If User Click Yes from confirmation box Then
Do_Funct_Yes
Else
Do_Funct_No
End If
Else
Do_Funct_B
End If


My problem is I cound't get the return value when user click YES or NO from
Javascript and let VB program understand this value to execute the next
lines. Could you give me your advises.

Thanks in advance.
 
K

Kris

Hi,

There is no direct communication between client script and server
script. You cannot directly understand the return value of javascript
messagbox .

If you need this, display messagebox through javascript and read the
return values in javascript. Based on the return values raise
appropraite event on the server.

Cheers,
Kris
 
S

sahooj

Hi,
Here is an code sample I used to pass back javascript value from HTML
to the sever and vice versa.

This code is in HTML part of the .aspx page.
---------------------------------
<input id="JSApprResp" type="hidden" name="JSApprResp">

function confApprove()
{
resp = window.confirm ('Are you sure, you want to Approve this
Record?');
document.Form2['JSApprResp'].value = resp;
}

---------------------------------------
I had a button defined on the aspx page as:

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


This is the code-behind page coding
**************************************************************
-----------------------------------
on Page_Load method, link your javascript method to the button.


btnApprove.Attributes("OnClick") =
"javascript:confApprove();"
-------------------------------------------


Create this user defined method in code-behind page

Sub doApproveIt(ByVal Source As Object, ByVal E As EventArgs) ' this
executes if value is TRUE , user confirms Approve

' JSApprResp is a HIDDEN field on this aspx HTML page.

' A javascript function confApprove() is called from HTML for
the button btnApprove
' to popup the message, and the script will return the value
' true or false. confApprove() method is registered on
' pageload event... btnApprove.Attributes("OnClick") =
"javascript:confApprove();"

Dim usrresp As Boolean = Request.Form("JSApprResp").ToString
If usrresp = True Then
createApproval("1") ' Approve was selected
Else
createDisApproval("2") ' Disapproval was selected
End If


End Sub
*******************


For me this works. Hope you can utilize it. Thanks.
 
B

bienwell

Your code works fine. But my problem is I only have one button in my page
that runs VB code to check some conditions . One of this condition calls the
confirmation message box. Like that, I cannot do
btnApprove.Attributes.Add("OnClick") = "javascript:confApprove();" because
I must need another button control to receive this attribute.

Like Kris said "There is no direct communication between client script
and server script. You cannot directly understand the return value of
javascript
message box ." I'm in server script and the code is based on one
condition to raise Javascript (confirmation message box), and receives the
return value from Client side to let server side understand and perform the
next lines in VB code. That's impossible. ASP.NET cannot hadle it . Is that
right ?

Thanks anyway.

bienwell
 
Joined
Jul 9, 2008
Messages
1
Reaction score
0
Hi I have same prob but i am getting error on
"Dim usrresp As Boolean = Request.Form("JSApprResp").ToString" this line can you help me.
 
Joined
Oct 21, 2008
Messages
1
Reaction score
0
Hi I have same prob but i am getting error on
"Dim usrresp As Boolean = Request.Form("JSApprResp").ToString" this line can you help me.

Hi i am 15 years old and i'm programming 1 year in vb

You get an error because you converting the value ti string but you dim it as boolean... Dim usrresp -->As Boolean<-- = Request.Form("JSApprResp").-->ToString<--

The right way:
Dim usrresp as Boolen
usrresp Request.Form("JSApprResp").
____________________________________
But also the posted value must be boolean
 
Joined
Nov 21, 2008
Messages
1
Reaction score
0
bienwell said:
Hi all,

I just have a question about using confirmation message box in ASP.NET
program. It's an emergency !!!

In my program, I have an ASP button runat='server' that calls a Sub
Function when users click this button. In this Sub Function, I have some
conditions:

If Cond_A Then
Display Confirmation box which has Yes and No buttton (Call
Javascript to display confirmation message box)
If User Click Yes from confirmation box Then
Do_Funct_Yes
Else
Do_Funct_No
End If
Else
Do_Funct_B
End If


My problem is I cound't get the return value when user click YES or NO from
Javascript and let VB program understand this value to execute the next
lines. Could you give me your advises.

Thanks in advance.


Hi bienwell,
Did you get to solve the problem you were having? I am having exactly the same need of yours as I need to pop up a confirm message box in the client site based on a condition that has to happen in the server, and then I need to be able to capture the answer from the client in order to continue running my code in the server.
I was wondering if you could help me with that at this point.


Thanks
 
Joined
Jul 27, 2009
Messages
3
Reaction score
0
I use this:

Code:
<asp:Button ID="btnDelete" runat="server" Text="Delete"
               OnClientClick="return confirm('Are you sure you want to delete?');" 
               OnClick="btnDelete_Click" />

protected void btnDelete_Click(object sender, EventArgs e)
{
    // your code for deleting here
}
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top