parameter from JScript to Asp.net

  • Thread starter Thread starter luke
  • Start date Start date
L

luke

Hi there,

Can anyone tell me a way to pass parameters from java script to ASP.net
(VB.net)?


Thanks
 
luke napisa³(a):
Hi there,

Can anyone tell me a way to pass parameters from java script to ASP.net
(VB.net)?

Sure:)

You have few options:
1) pass it as parameter in url while redirecting with location.replace()
2) pass it as field in form (most likely hidden field)
3) pass it in cookie which is modified from js.
 
In the application's html, the code is:

<SCRIPT language="JAVASCRIPT" .....
..........
function update_temperature(x, y) {
document.Form1.txtTemperatureX.value= x;
document.Form1.txtTemperatureY.value= y;
}

........

I can pass the values to txtTemperatureX and Y (only visible) in server
section, however when I click on one button which suppose to pick up the
value of txtTemperatureX and Y, but it is not at all,. Simply not updating
the page and change the old value from txtTemperatureX and Y.

If any help would be appreciated.

Thanks.

I try to find a better way to pass parameters
 
Hi,

Przemek said:
luke napisa³(a):

Sure:)

You have few options:
1) pass it as parameter in url while redirecting with location.replace()
2) pass it as field in form (most likely hidden field)
3) pass it in cookie which is modified from js.

All these solution imply a postback. I would like to add

4) AJAX

Greetings,
Laurent
 
The most common way is using hidden input fields:

<input type=hidden id=myParameter runat=server>

They are accessible on both client and server.
 
In the application's html, the code is:

<SCRIPT language="JAVASCRIPT" .....
.........
function update_temperature(x, y) {
document.Form1.txtTemperatureX.value= x;
document.Form1.txtTemperatureY.value= y;
}

.......

I can pass the values to txtTemperatureX and Y (only visible) in server
section, however when I click on one button which suppose to pick up the
value of txtTemperatureX and Y, but it is not at all,. Simply not updating
the page and change the old value from txtTemperatureX and Y.

If any help would be appreciated.

Hmm - when you say "click on one button", is this the button which causes
the postback? In which case, I wonder if you are populating the values of
the two textboxes every time the page loads... If this is the case, then the
form fields will always have their original values e.g.

protected void Page_Load(object sender, System.EventArgs e)
{
// fetch data
// populate form fields
}

should be

protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostback)
{
// fetch data
// populate form fields
}
}
 
I did use the approach as you said, however it seems the java script in html
didn't refresh the page at all, or somehow it postback to the old value but
it visually looks like the new value has been changed.
 
I did use the approach as you said, however it seems the java script in
html didn't refresh the page at all, or somehow it postback to the old
value but it visually looks like the new value has been changed.

I have no idea what you're doing...

Please post the complete code for the page in question...
 
Back
Top