473,503 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a variable value from Javascript to asp.net server variable

Hi all,

I am using javascript confirm() function to get user's confirmation
from codebehind after a condition is met. I don't want to attach the
function to the button on page load. When I submit the page, I want to
check some business rules, and based on the response from the database,
if the response is Yes, I need to display a confirmation alert to user.
When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.
__________________________________________________ _________
If Trim(Message) <"" Then
Dim strScript As String = "<script language=JavaScript>"
strScript += "var bAnswer = confirm(""" & Trim(Message) & """);"
strScript += "</script>"

If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
End If
__________________________________________________ _________

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user. But I don't have a way
to get the value of what an user have selected from the confirmation
alert box. I don't want to resubmit the form since I would loose some
of the business rules.

If I could pass the javascript variable "bAnswer" value to a server
variable, that would be great.

Any help is appreciated.
Thanks.

Jan 2 '07 #1
2 2889
there is no way to pass the data back other than some sort of postback.
usually you put the answer into a hidden field and do a submit.

your confirm only display when the page is rerendered by the browser, so
you will need to keep the logic for the next pass in state.

render something like:

Page.RegisterStartupScript("myscript",string.Forma t(@"
<input type=hidden name=txtConfirm id=txtConfirm >
<script>
document.getElementById('txtConfirm').value = confirm('%0');
document.forms[0].submit();
</script>
",Message));
-- bruce (sqlwork.com)

shil wrote:
Hi all,

I am using javascript confirm() function to get user's confirmation
from codebehind after a condition is met. I don't want to attach the
function to the button on page load. When I submit the page, I want to
check some business rules, and based on the response from the database,
if the response is Yes, I need to display a confirmation alert to user.
When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.
__________________________________________________ _________
If Trim(Message) <"" Then
Dim strScript As String = "<script language=JavaScript>"
strScript += "var bAnswer = confirm(""" & Trim(Message) & """);"
strScript += "</script>"

If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
End If
__________________________________________________ _________

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user. But I don't have a way
to get the value of what an user have selected from the confirmation
alert box. I don't want to resubmit the form since I would loose some
of the business rules.

If I could pass the javascript variable "bAnswer" value to a server
variable, that would be great.

Any help is appreciated.
Thanks.
Jan 2 '07 #2
As Bruce said, you will have to have a sort of postback.

See if this helps you:

http://www.usableasp.net/DeveloperPa...rAndClient.htm

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"shil" <jo******@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
Hi all,

I am using javascript confirm() function to get user's confirmation
from codebehind after a condition is met. I don't want to attach the
function to the button on page load. When I submit the page, I want to
check some business rules, and based on the response from the database,
if the response is Yes, I need to display a confirmation alert to user.
When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.
__________________________________________________ _________
If Trim(Message) <"" Then
Dim strScript As String = "<script language=JavaScript>"
strScript += "var bAnswer = confirm(""" & Trim(Message) & """);"
strScript += "</script>"

If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
End If
__________________________________________________ _________

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user. But I don't have a way
to get the value of what an user have selected from the confirmation
alert box. I don't want to resubmit the form since I would loose some
of the business rules.

If I could pass the javascript variable "bAnswer" value to a server
variable, that would be great.

Any help is appreciated.
Thanks.

Jan 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
72108
by: Jonas Daunoravicius | last post by:
The subject pretty much sums up what I need to do. Here is what I have so far, but still can't figure out how to get it working: <script language="javascript" type="text/javascript"> function...
12
6508
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
3
14906
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
8
3654
by: Mike Fellows | last post by:
Ok, im not sure if this is at all possible and if it is how i go about it is beyond me i have a piece of client side code that requires a piece of data from the server side (an ID number in this...
5
3512
by: Paul | last post by:
Just wondering if someone could provide an example of passing a variable from the code behind to javascript in vb. I want to have one control have focus with the page loading with one condition...
1
11847
by: | last post by:
Hi, 1st, I did a search and could not find any info on this, the Google results were good, but I'm still have issues...So any help will be great. I have a frame page, which contains 3 frames...
6
5563
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
5
4995
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
5
10267
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.