|
-
Nov 2nd, 2006, 08:19 AM
#1
Thread Starter
Lively Member
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
-
Nov 2nd, 2006, 01:18 PM
#2
Re: Sharing a value between client side and server side code.
Try this
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'add confirmation message to send button
btnSend.Attributes("onclick") = "javascript:return confirm('Are you sure you want send?');"
End If
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
me.txtboxname.value="Welcome"
End Sub
-
Nov 3rd, 2006, 12:13 AM
#3
Thread Starter
Lively Member
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
-
Nov 3rd, 2006, 08:47 AM
#4
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?
-
Nov 3rd, 2006, 10:08 PM
#5
Thread Starter
Lively Member
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
-
Nov 4th, 2006, 02:18 AM
#6
Frenzied Member
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
-
Nov 4th, 2006, 05:39 AM
#7
Thread Starter
Lively Member
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
-
Nov 4th, 2006, 06:45 AM
#8
Frenzied Member
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.
-
Nov 5th, 2006, 06:00 PM
#9
Re: Sharing a value between client side and server side code.
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'add confirmation message to send button
btnSend.Attributes("onclick") = "javascript:return confirm('Are you sure you want send?');"
End If
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
'Do server side code to see if a payment is done
If paymentIsDone Then
Page.RegisterStartupScript("ClientSideScript", "<script>alert('Cannot delete record --Payment done');</script>")
Else
'Do delete
End If
End Sub
-
Nov 6th, 2006, 10:01 PM
#10
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|