Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 02-14-2006, 02:14 PM   #1
Default Confirmation Message Box (return Value from Javascript to ASP.NET program ). Please help !!!


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.




bienwell
  Reply With Quote
Old 02-14-2006, 07:35 PM   #2
Kris
 
Posts: n/a
Default Re: Confirmation Message Box (return Value from Javascript to ASP.NET program ). Please help !!!

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

  Reply With Quote
Old 02-14-2006, 10:01 PM   #3
sahooj@gmail.com
 
Posts: n/a
Default Re: Confirmation Message Box (return Value from Javascript to ASP.NET program ). Please help !!!

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.

  Reply With Quote
Old 02-17-2006, 02:42 PM   #4
bienwell
 
Posts: n/a
Default Re: Confirmation Message Box (return Value from Javascript to ASP.NET program ). Please help !!!

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



<> wrote in message
news: ups.com...
> 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.
>



  Reply With Quote
Old 08-26-2008, 06:23 AM   #5
priyappated@gmail.com
Junior Member
 
Join Date: Jul 2008
Posts: 1
Question

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.
priyappated@gmail.com is offline   Reply With Quote
Old 10-21-2008, 01:31 PM   #6
hotkill3r1h4ck3r
Junior Member
 
Join Date: Oct 2008
Posts: 1
Default

Quote:
Originally Posted by
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
hotkill3r1h4ck3r is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump