Send Value From Client-Side Script To Server

G

Guadala Harry

I have some client-side JavaScript that, among other things, calculates the
value of a variable (myVar). On the server I have a stored procedure that
needs to somehow receive as an input parameter the value of myVar. I need to
know how to get the value of myVar from the script up to the server.
Specifically, I'd like to have the following happen when the user clicks a
button in the browser:
1. The client-side script executes (and determines the value of myVar).
2. A postback is initiated - at which time the value of myVar is sent to an
aspx.cs function which ultimately...
3. executes a stored procedure (which receives the value of myVar as an
input parameter).

This is a very important piece of a larger project... any help would be
greatly appreciated - including any JavaScript syntax, as I'm a but rusty on
my JavaScript skills.

Thanks!

-GH
 
G

Guadala Harry

Please note: I only need help with getting the value from the client-side
script to the server-side aspx.cs function. I can take it from there -
Thanks!
 
L

Lau Lei Cheong

You can make the button to be a client-side button that invokes the script,
then store the value to a hidden control with "runat=server" and finally
call a server-side button to post the data to server(possibly with a
document.FindElementbyId().click()).
If there should be only one button on the form, you may want to try an
ImageButton with "white" image.
 
G

Guadala Harry

How do I do the following part of what you recommend - do you have specific
JavaScript Syntax?
<<...and finally call a server-side button to post the data to server...>

Does anyone have an easier way to accomplish what I'm after?

Thanks for your input so far - GH.
 
L

Lau Lei Cheong

Use the statement:
document.FindElementbyId("bt_submit").click();
where bt_Submit is a button with "runat=server" & " id='bt_submit'
"properties set.

I've already suggested that in my last post.

You'll have to follow this kind of approach as there's no easier method to
pass value to server-side using form-submittion(get/post)
 
G

Guadala Harry

While it got me going in the right direction, I had no luck with
document.FindElementbyId("bt_submit").click(); But for those of you who
may be interested in the outcome of this thread, a variation of the
recommendation is what works:

This is the hyperlink that, when clicked, executes the client-side
JavaScript function:
<a id="HyperLink1" href="javascript:TestPostBackFromJavaScript()" >Test Save
From JavaScript</a>

Here is the JavaScript Function
function TestPostBackFromJavaScript() {
document.all("btnSaveChanges").click();
}

That JavaScript function effectively "clicks" the following ASP.NET button:
<asp:Button id="btnSaveChanges" EnableViewState="true"
CommandName="SaveChanges" Visible="true" Width="115" runat="server"
Text="Save Changes"></asp:Button>

Thanks to Lau Lei Cheong for pointing me in the right direction.

GH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top