473,486 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

return javascript value from asp.net button

Hi there,
Is there a way to call a javascript function and return its value, from
inside an asp.net button ??

--
Ad****@hotmail.com
Nov 19 '05 #1
4 5969
In your Page_Load event you can add a line such as the following:

[C#]
button.Attributes["onclick"] = "alert(myFunc());";
or
button.Attributes.Add("onclick", "alert(MyFunc());");

This will manipulate the HTML output to include the client side event handler.

HTH
----
Dave Fancher
http://davefancher.blogspot.com

"ACaunter" wrote:
Hi there,
Is there a way to call a javascript function and return its value, from
inside an asp.net button ??

--
Ad****@hotmail.com

Nov 19 '05 #2
thanks for the reply...
I'm trying to get the user's time (hours and minutes).. and my code is in
the page load, not a button (sorry),... how can i call this function , not to
show it in a messagebox, but to just store it... like:
dim x as string = javafunction()
i have 2 seperate function , 1 for hour and 1 for minute...

"Dave Fancher" wrote:
In your Page_Load event you can add a line such as the following:

[C#]
button.Attributes["onclick"] = "alert(myFunc());";
or
button.Attributes.Add("onclick", "alert(MyFunc());");

This will manipulate the HTML output to include the client side event handler.

HTH
----
Dave Fancher
http://davefancher.blogspot.com

"ACaunter" wrote:
Hi there,
Is there a way to call a javascript function and return its value, from
inside an asp.net button ??

--
Ad****@hotmail.com

Nov 19 '05 #3
What you want to do is not directly possible. You'll have to develop a
"proxy" page or something that executes the client side java script to
retrieve the values that you want and stores the results in a hidden field
and automatically posts (see form.submit()) the form back to the server
which, in turn stores the values of the hidden fields in (most likely) a
session object then redirects the user to the page with which s/he will
interact.

If you are trying to just place a timestamp when the user posts the form,
you wouldn't need a proxy page, you could just add a client side submit
event handler that executes the code you want and saves it in a hidden
field. Never underestimate the power of DHTML.

--
Dave Fancher
http://davefancher.blogspot.com
"ACaunter" <Ad****@hotmail.com> wrote in message
news:D4**********************************@microsof t.com...
thanks for the reply...
I'm trying to get the user's time (hours and minutes).. and my code is in
the page load, not a button (sorry),... how can i call this function , not
to
show it in a messagebox, but to just store it... like:
dim x as string = javafunction()
i have 2 seperate function , 1 for hour and 1 for minute...

"Dave Fancher" wrote:
In your Page_Load event you can add a line such as the following:

[C#]
button.Attributes["onclick"] = "alert(myFunc());";
or
button.Attributes.Add("onclick", "alert(MyFunc());");

This will manipulate the HTML output to include the client side event
handler.

HTH
----
Dave Fancher
http://davefancher.blogspot.com

"ACaunter" wrote:
> Hi there,
> Is there a way to call a javascript function and return its value, from
> inside an asp.net button ??
>
> --
> Ad****@hotmail.com

Nov 19 '05 #4
Add a hiden field with the runat=server attribute.

the script would do something like:
document.forms[0].hiddenFieldElement.value='Hello World";
document.forms[0].submit();

now the problem you are going to have is that you can't really respond to an
event for this...so in your page load you'll have to have....

(VB.NET)
If hiddenFieldElement.value<>String.Empty then
''...do whatever you need to and then set the hidden field value to
String.Empty
hiddenFieldElement.value=String.Empty
End if

(C#)
if(hiddenFieldElement.value!=string.Empty){
//Process Evenything
hiddenFieldElement.value=string.Empty
}

"ACaunter" <Ad****@hotmail.com> wrote in message
news:4D**********************************@microsof t.com...
Hi there,
Is there a way to call a javascript function and return its value, from
inside an asp.net button ??

--
Ad****@hotmail.com

Nov 19 '05 #5

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

Similar topics

0
3425
by: Mike Copeland | last post by:
In the following code I am calculating 2 values when the "Compute Distance" button is pressed. I would like to find a way to "return" both value to the form so I can show both when the calculation...
4
2316
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
1
5398
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
5
3956
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
4
8505
by: phil | last post by:
Is there an elegant way that I can return a value from a JavaScript function to ASP.NET? I want to have a popup confirmation dialog using JavaScript and only have a button control execute its ASP...
18
2238
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
13
3982
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
1
2604
by: jhoff | last post by:
I'm trying to use javascript to execute code when the enter key is pressed in a text box. Basically, I'm doing this... <html> <body onload="load()" onunload="GUnload()"> <form name=zipform>...
2
3059
by: thuythu | last post by:
Please help me.... I used and Javascript to view the data. But when i click button open a popup windows, then select data and click save button. The popup close and return the main page, but the...
1
2277
by: Sudarhan | last post by:
Hello frnds I have created a webbased form using asp and javascript .. while submitting the form i am validating the fields in the form .it validates the field and returns alert message. but when...
0
7099
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
6964
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
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7319
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
4559
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
3069
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
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.