Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Wednesday, March 28, 2012

text box value does not match value on postback

Hi All,

I have a text box that is currently being set by a javascript function
as a running total. the javascript is working fine, as values are
changing the running total is being set correctly in the text box.
When the page is posted to the button OnClick event, the value of the
text box is what was previously defaulted as part of the Page_Load
event.

Any ideas on what is happening here or how to fix this issue?

Thanks ALOT in advance.<allan.palmer@.cit.comwrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...

Quote:

Originally Posted by

Any ideas on what is happening here or how to fix this issue?


Show your code...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
<allan.palmer@.cit.comwrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...

Quote:

Originally Posted by

Hi All,
>
I have a text box that is currently being set by a javascript function
as a running total. the javascript is working fine, as values are
changing the running total is being set correctly in the text box.
When the page is posted to the button OnClick event, the value of the
text box is what was previously defaulted as part of the Page_Load
event.
>
Any ideas on what is happening here or how to fix this issue?
>
Thanks ALOT in advance.


Hi Allan,

The "problem" is that the POST value of the textbox is set *before*
Page_Load, then you are putting a default value in there during Page_Load
(overwriting the POST value), then your button click event is fired and you
see the Page_Load value instead of the POST value.

In your Page_Load, only set the default value of the textbox on the initial
page load:

if (!IsPostBack)
{
// Set default value.
}

text box value does not match value on postback

Hi All,
I have a text box that is currently being set by a javascript function
as a running total. the javascript is working fine, as values are
changing the running total is being set correctly in the text box.
When the page is posted to the button OnClick event, the value of the
text box is what was previously defaulted as part of the Page_Load
event.
Any ideas on what is happening here or how to fix this issue?
Thanks ALOT in advance.<allan.palmer@.cit.com> wrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...

> Any ideas on what is happening here or how to fix this issue?
Show your code...
Mark Rae
ASP.NET MVP
http://www.markrae.net
<allan.palmer@.cit.com> wrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...
> Hi All,
> I have a text box that is currently being set by a javascript function
> as a running total. the javascript is working fine, as values are
> changing the running total is being set correctly in the text box.
> When the page is posted to the button OnClick event, the value of the
> text box is what was previously defaulted as part of the Page_Load
> event.
> Any ideas on what is happening here or how to fix this issue?
> Thanks ALOT in advance.
Hi Allan,
The "problem" is that the POST value of the textbox is set *before*
Page_Load, then you are putting a default value in there during Page_Load
(overwriting the POST value), then your button click event is fired and you
see the Page_Load value instead of the POST value.
In your Page_Load, only set the default value of the textbox on the initial
page load:
if (!IsPostBack)
{
// Set default value.
}

Thursday, March 22, 2012

textbod id changed automatically

Hi There,
I've a master page, and the content place i'v a page which has a text box
name tbCity. I would like to use javascript to find out that was blank or
not.
When i look at the sourcecode th text box id was chagned to
ctl00_Main_tbCity
why is it like this.
ThanksHello Ganesh

> I've a master page, and the content place i'v a page which has a text box
> name tbCity. I would like to use javascript to find out that was blank or
> not.
document.getElementById(<Control.ClientID> ).value == '';

> When i look at the sourcecode th text box id was chagned to
> ctl00_Main_tbCity
> why is it like this.
On the server side, ASP.NET has features like, nesting Controls, Namespaces,
etc..
that help to have consistente IDs. That means also, you can have more then
on of the same IDs on a page.
When ASP.NET rendered the code for viewing in a Html Browser, there are no
features like on the server side.
Here you can`t have more then one identic ID for a control.
So ASP.NET generates automatically IDs and Names where based on the control
hierarchy.
The <Control>.ClientID represents the ID Attribute on the clientside.
The <Control>.UniqueID represents the NAME Attribute on the clientside.
I have written a german article about identification of ASP.NET Controls.
Maybe you`r be able to understand the Google Translated Page:
-
http://translate.google.com/transla...aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
Hi Peter,
Thanks for your help.
"Peter Bucher [MVP]" <peter.bucher@.aspnetzone.de> wrote in message
news:OxXvYyf0HHA.1184@.TK2MSFTNGP04.phx.gbl...
> Hello Ganesh
>
> document.getElementById(<Control.ClientID> ).value == '';
>
> On the server side, ASP.NET has features like, nesting Controls,
> Namespaces, etc..
> that help to have consistente IDs. That means also, you can have more then
> on of the same IDs on a page.
> When ASP.NET rendered the code for viewing in a Html Browser, there are no
> features like on the server side.
> Here you can`t have more then one identic ID for a control.
> So ASP.NET generates automatically IDs and Names where based on the
> control hierarchy.
> The <Control>.ClientID represents the ID Attribute on the clientside.
> The <Control>.UniqueID represents the NAME Attribute on the clientside.
> I have written a german article about identification of ASP.NET Controls.
> Maybe you`r be able to understand the Google Translated Page:
> -
> http://translate.google.com/transla...aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
> http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
"Ganesh" <gsganesh@.yahoo.com> wrote in message
news:OO75qTf0HHA.1100@.TK2MSFTNGP06.phx.gbl...

> I've a master page, and the content place i'v a page which has a text box
> name tbCity. I would like to use javascript to find out that was blank or
> not.
> When i look at the sourcecode th text box id was chagned to
> ctl00_Main_tbCity
if (document.getElementById(<%=tbCity.ClientID%> ).value == '')
{
// do something
}

> why is it like this.
To guarantee uniqueness of ID.
Mark Rae
ASP.NET MVP
http://www.markrae.net