473,569 Members | 2,700 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=JavaSc ript>"
strScript += "var bAnswer = confirm(""" & Trim(Message) & """);"
strScript += "</script>"

If (Not Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript", 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 2898
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.RegisterSt artupScript("my script",string. Format(@"
<input type=hidden name=txtConfirm id=txtConfirm >
<script>
document.getEle mentById('txtCo nfirm').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=JavaSc ript>"
strScript += "var bAnswer = confirm(""" & Trim(Message) & """);"
strScript += "</script>"

If (Not Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript", 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.goog legroups.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=JavaSc ript>"
strScript += "var bAnswer = confirm(""" & Trim(Message) & """);"
strScript += "</script>"

If (Not Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript", 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
72127
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 fillForm() { // split the query string into pieces var qs = location.search.substr(location.search.indexOf("?")+1); qs = qs.split("&"); alert(qs);...
12
6522
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 courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html ...
3
14916
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
8
3662
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 case) how can i pass the data from one side to the other, or retrieve it from the webform on the client side? i hope ive explained this...
5
3516
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 and have another control with focus after the page loads from a different condition. A gets set in the code aspx.vb file and the script might look...
1
11853
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 (Left, Content, and Footer) In the content page, I have a checkbox, which value is a number (i.e. 500). I would like that, when a user clicks on this...
6
5574
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 object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not...
5
5000
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
10276
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 may also open up new chat windows with other members (just not the same one). - Each chat page is opened with the member name as the window name. -...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
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 we have to send another system

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.