Results 1 to 10 of 10

Thread: Sharing a value between client side and server side code.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    102

    Sharing a value between client side and server side code.

    Hello Friends

    I need to take an action at server side depending on the choice the user has made at client (client side message box)

    I have created a text box and assigned the value from the javascript and tried to access it from the serverside

    code. It works fine in the standalone page, but when i try the same code inside a content page, nothing

    happens

    Code inside a standalone page

    function GetConfirm()
    {
    var ReturnedValue = confirm("Are you sure?");
    form1.txtboxName.value= "Welcome";
    }

    Thanks for your time
    Sara

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Sharing a value between client side and server side code.

    Try this
    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         If Not Page.IsPostBack Then
    3.             'add confirmation message to send button
    4.             btnSend.Attributes("onclick") = "javascript:return confirm('Are you sure you want send?');"
    5.                End If
    6.     End Sub
    7.     Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    8.         me.txtboxname.value="Welcome"
    9.     End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    102

    Re: Sharing a value between client side and server side code.

    Thank you very much for your answer.
    I really appreciate you answering so many newbie questions. I am sure
    lot many people feel the same about your replies

    The solution you have given is working fine. But the mistake i had done is that I have not explained my challenge completely.

    On click of the DELETE button I have to do 2 validations

    1) first check if any payments have been done for that bill. if YES display a messege "Cannot delete record --Payment done"

    2) if no payment is done then display message " Do you want to delete this record" -- if yes delete the record

    How do i handle 2 validations on click of the same button ?

    Thank you for your time and reply


    Sara

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Sharing a value between client side and server side code.

    Can you determine if a payment is done with out making a post back to the server?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    102

    Re: Sharing a value between client side and server side code.

    Thank you for the reply

    I guess i have to do a postback to the server to find out if a payment has been done......The payment details (EMI) are in the details table and the Loan details is in the master, If a EMI has been paid for a particula loan then i do not want to delete that loan record

    Is it possible to call a function on click of the button which will handle more than one condition ?

    Thank you for your time

    Sara

  6. #6
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Sharing a value between client side and server side code.

    dont know i understand correctly, but yes, you can do as many things you like in a single method.
    Or even better (just my style), create on method for each of the actions you wnat to perform, and call them in order, depending on their return values, from the method called by the button (or in the button's click event)
    like: (just pseudo code ok?)
    Code:
    Button Click
    If (PaymentsMade)
      if (Delete)
        DoThis...
       else
         DoThat
    End
    Bool PaymentsMade
       ...query database to see if payments is made
       ...return true or false
    End
    Bool Delete
      string script = "call javascript"...not sure how to get yes/no back here...anyone?
       return true or false
    
    End

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    102

    Re: Sharing a value between client side and server side code.

    Hi StrangerInBeijing

    Thanks for your Time and Reply.

    Looks good. but i do not know how to implement it. Guess i will need a bit more handholding


    Sara

  8. #8
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Sharing a value between client side and server side code.

    Seeing I dont know how to pop a confirm box and get the return value from the code behind, just wait until the Frog comes around. You'll soon learn, that mother got an answer to everything.

  9. #9
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Sharing a value between client side and server side code.

    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         If Not Page.IsPostBack Then
    3.             'add confirmation message to send button
    4.             btnSend.Attributes("onclick") = "javascript:return confirm('Are you sure you want send?');"
    5.                End If
    6.     End Sub
    7.     Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    8.         'Do server side code to see if a payment is done
    9.         If paymentIsDone Then
    10.             Page.RegisterStartupScript("ClientSideScript", "<script>alert('Cannot delete record --Payment done');</script>")
    11.         Else
    12.             'Do delete
    13.         End If
    14.     End Sub

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    102

    Re: Sharing a value between client side and server side code.

    Thanks for the reply


    Well this will first display a message saying "'Are you sure you want send" ?

    I need the payment checking part to happen first, so that there is only one message "Cannot delete as a payment is done" ...else the program will ask do you want to delete the record, then say " cannot delete"

    All help is truely appreciated

    regards
    Sara
    Last edited by sara_23apr; Nov 6th, 2006 at 10:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width