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

Discussion in 'ASP .Net' started by bienwell, Feb 14, 2006.

  1. bienwell

    bienwell Guest

    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, Feb 14, 2006
    #1
    1. Advertising

  2. bienwell

    Kris Guest

    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
    Kris, Feb 14, 2006
    #2
    1. Advertising

  3. bienwell

    Guest

    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.
    , Feb 14, 2006
    #3
  4. bienwell

    bienwell Guest

    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:...
    > 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.
    >
    bienwell, Feb 17, 2006
    #4
  5. bienwell

    Joined:
    Jul 9, 2008
    Messages:
    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.
    , Aug 26, 2008
    #5
  6. bienwell

    hotkill3r1h4ck3r

    Joined:
    Oct 21, 2008
    Messages:
    1
    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, Oct 21, 2008
    #6
  7. bienwell

    agrFree

    Joined:
    Nov 21, 2008
    Messages:
    1

    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
    agrFree, Nov 22, 2008
    #7
  8. bienwell

    Vangi

    Joined:
    Jul 27, 2009
    Messages:
    3
    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
    }
    
    Vangi, Aug 4, 2009
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Clarke

    How to show Confirmation message box?

    Ron Clarke, Jan 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    9,366
    Steve C. Orr [MVP, MCSD]
    Jan 15, 2004
  2. bienwell
    Replies:
    2
    Views:
    5,043
  3. bienwell
    Replies:
    5
    Views:
    5,198
    bienwell
    Aug 13, 2006
  4. =?Utf-8?B?Ym9iYnk=?=

    Message Box for confirmation

    =?Utf-8?B?Ym9iYnk=?=, Sep 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    447
    David Wier
    Sep 21, 2007
  5. Michael Winter

    Confirmation message box on a link click?

    Michael Winter, Feb 16, 2004, in forum: Javascript
    Replies:
    2
    Views:
    107
    Craig
    Feb 18, 2004
Loading...

Share This Page