![]() |
|
|
|||||||
![]() |
ASP Net - Confirmation Message Box (return Value from Javascript to ASP.NET program ). Please help !!! |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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. |
|
|
|
#4 |
|
Posts: n/a
|
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. > |
|
|
|
#5 |
|
Junior Member
Join Date: Jul 2008
Posts: 1
|
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. |
|
|
|
|
|
#6 | |
|
Junior Member
Join Date: Oct 2008
Posts: 1
|
Quote:
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 |
|
|
|
|