473,516 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Client side changes not reflected in page

Hi everyone!

I have a hidden input field in a form which I change in some occasions on
the client using javascript,
but when I use "view source" I can't see these changes reflected on the page!

Does anyone know what I should do in order for the page to know the change?
(Tried with enableviewstate=false, true, whatever, didn't work)

I would like to have the change reflected in the page without doing a
postback or on the postback!

Is this possible? Thanks in advance!
Feb 1 '07 #1
24 6611
Stick this in the browser addressbar and you'll see the changes:
javascript:document.write("<xmp>"+document.documen tElement.innerHTML+
"</xmp>");

Dynamic updates to the HTML DOM don't usually show up with "View Source".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"patrickdrd" wrote:
Hi everyone!

I have a hidden input field in a form which I change in some occasions on
the client using javascript,
but when I use "view source" I can't see these changes reflected on the page!

Does anyone know what I should do in order for the page to know the change?
(Tried with enableviewstate=false, true, whatever, didn't work)

I would like to have the change reflected in the page without doing a
postback or on the postback!

Is this possible? Thanks in advance!
Feb 1 '07 #2
view source shows what the server sent, not the current state of the
page. if javascript changed anything it is not reflected in the source.

for example view source of this page looks nothing like the rendered html:

<html>
<body>
<script>
for(var i=0; i< 100; ++i) document.write('hello ' + i + '<br>');
</script>
</body>
</html>
-- bruce (sqlwork.com)
patrickdrd wrote:
Hi everyone!

I have a hidden input field in a form which I change in some occasions on
the client using javascript,
but when I use "view source" I can't see these changes reflected on the page!

Does anyone know what I should do in order for the page to know the change?
(Tried with enableviewstate=false, true, whatever, didn't work)

I would like to have the change reflected in the page without doing a
postback or on the postback!

Is this possible? Thanks in advance!
Feb 1 '07 #3
Yes, but when the page is posted back to the server,
the change that javascript made isn't recognized by the server code,
while the server recognizes changes made through user input,
it doesn't know changes made by javascript! Why?

"Peter Bromberg [C# MVP]" wrote:
Stick this in the browser addressbar and you'll see the changes:
javascript:document.write("<xmp>"+document.documen tElement.innerHTML+
"</xmp>");

Dynamic updates to the HTML DOM don't usually show up with "View Source".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"patrickdrd" wrote:
Hi everyone!

I have a hidden input field in a form which I change in some occasions on
the client using javascript,
but when I use "view source" I can't see these changes reflected on the page!

Does anyone know what I should do in order for the page to know the change?
(Tried with enableviewstate=false, true, whatever, didn't work)

I would like to have the change reflected in the page without doing a
postback or on the postback!

Is this possible? Thanks in advance!
Feb 1 '07 #4
Yes, but when the page is posted back to the server,
the change that javascript made isn't recognized by the server code,
while the server recognizes changes made through user input,
it doesn't know changes made by javascript! Why?
"bruce barker" wrote:
view source shows what the server sent, not the current state of the
page. if javascript changed anything it is not reflected in the source.

for example view source of this page looks nothing like the rendered html:

<html>
<body>
<script>
for(var i=0; i< 100; ++i) document.write('hello ' + i + '<br>');
</script>
</body>
</html>
-- bruce (sqlwork.com)
patrickdrd wrote:
Hi everyone!

I have a hidden input field in a form which I change in some occasions on
the client using javascript,
but when I use "view source" I can't see these changes reflected on the page!

Does anyone know what I should do in order for the page to know the change?
(Tried with enableviewstate=false, true, whatever, didn't work)

I would like to have the change reflected in the page without doing a
postback or on the postback!

Is this possible? Thanks in advance!
Feb 1 '07 #5
On Feb 1, 2:34 am, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Stick this in the browser addressbar and you'll see the changes:
javascript:document.write("<xmp>"+document.documen tElement.innerHTML+
"</xmp>");
[try to avoid "top posting"... ;) ]

Or you could use FireFox together with FireBug from which you have the
possibility to both INSPECT the DOM in addition to actually do CHANGES
to the DOM and CSS in addition to setting breakpoints in JavaScript
code...
Marvelous tool :)
I LOVE FireBug!!
..t

--
http://ajaxwidgets.com
Free ASP.NET Ajax Widgets NOW!

Feb 1 '07 #6
It seems to me that Bruce's response was quite explanatory, read it again for
the answer.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"patrickdrd" wrote:
Yes, but when the page is posted back to the server,
the change that javascript made isn't recognized by the server code,
while the server recognizes changes made through user input,
it doesn't know changes made by javascript! Why?
"bruce barker" wrote:
view source shows what the server sent, not the current state of the
page. if javascript changed anything it is not reflected in the source.

for example view source of this page looks nothing like the rendered html:

<html>
<body>
<script>
for(var i=0; i< 100; ++i) document.write('hello ' + i + '<br>');
</script>
</body>
</html>
-- bruce (sqlwork.com)
patrickdrd wrote:
Hi everyone!
>
I have a hidden input field in a form which I change in some occasions on
the client using javascript,
but when I use "view source" I can't see these changes reflected on the page!
>
Does anyone know what I should do in order for the page to know the change?
(Tried with enableviewstate=false, true, whatever, didn't work)
>
I would like to have the change reflected in the page without doing a
postback or on the postback!
>
Is this possible? Thanks in advance!
Feb 1 '07 #7
Well, ok, forget about the page's source,
my mistake mentioning this,
my real problem is that the variable show its 'original' value when
submitted to the server and not the one that javascript changed to!
Why isn't that variable/field 'refreshed'?
Do I need to do something (like a 'refresh')?

"Peter Bromberg [C# MVP]" wrote:
It seems to me that Bruce's response was quite explanatory, read it again for
the answer.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"patrickdrd" wrote:
Yes, but when the page is posted back to the server,
the change that javascript made isn't recognized by the server code,
while the server recognizes changes made through user input,
it doesn't know changes made by javascript! Why?
"bruce barker" wrote:
view source shows what the server sent, not the current state of the
page. if javascript changed anything it is not reflected in the source.
>
for example view source of this page looks nothing like the rendered html:
>
<html>
<body>
<script>
for(var i=0; i< 100; ++i) document.write('hello ' + i + '<br>');
</script>
</body>
</html>
>
>
-- bruce (sqlwork.com)
>
>
patrickdrd wrote:
Hi everyone!

I have a hidden input field in a form which I change in some occasions on
the client using javascript,
but when I use "view source" I can't see these changes reflected on the page!

Does anyone know what I should do in order for the page to know the change?
(Tried with enableviewstate=false, true, whatever, didn't work)

I would like to have the change reflected in the page without doing a
postback or on the postback!

Is this possible? Thanks in advance!
>
Feb 1 '07 #8
"patrickdrd" <pa********@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...

Patrick,
Well, ok, forget about the page's source,
my mistake mentioning this,
It's a common misconception... :-)
my real problem is that the variable show its 'original' value when
submitted to the server and not the one that javascript changed to!
Why isn't that variable/field 'refreshed'?
Do I need to do something (like a 'refresh')?
This, however, is a different issue...

Client-side data changes, whether caused by user typing or JavaScript,
should certainly survive a postback.

You'll need to post your code...
Feb 1 '07 #9
I've had the exact problem both in ASP.NET 1.1 and now I'm facing it in 2.0
as well!

Well, the case is this
(I'll mention the 1.1 case, which is easier to tell):

on a user input form (data entry - update a customer, let's say),
the user types the new data and presses the update button to commit the
changes,
however, javascript is called before the postback in order to validate the
input values,
if something goes wrong prompts the user to correct,
and, when everything is ok, posts the page to the server.

If I change a single value on a single field with javascript on this example
and then post back the page to the server, that change can't be seen by the
server,
while user values and changes of the fields can!

Why? How is that?

"Mark Rae" wrote:
"patrickdrd" <pa********@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...

Patrick,
Well, ok, forget about the page's source,
my mistake mentioning this,

It's a common misconception... :-)
my real problem is that the variable show its 'original' value when
submitted to the server and not the one that javascript changed to!
Why isn't that variable/field 'refreshed'?
Do I need to do something (like a 'refresh')?

This, however, is a different issue...

Client-side data changes, whether caused by user typing or JavaScript,
should certainly survive a postback.

You'll need to post your code...
Feb 1 '07 #10
"patrickdrd" <pa********@discussions.microsoft.comwrote in message
news:C6**********************************@microsof t.com...
Why? How is that?
For the second time, you'll need to post your code...
Feb 1 '07 #11
Hi Patrick,

I see the problem is that you don't quite understand how it works. Every
time you request a page from the browser, asp.net generates a HTML document
that is sent back and parsed by the browser. In addition to that browser
builds DOM objects based on parsed document so you could interact with
document on the client side via JavaScript / VBScript. That’s the bit you
seem to understand. Now (simplifying), if you want to send page back to the
server, only small part of the information is passed in POST request - a
special form is built to store values for <inputcontrols only (textbox,
radio button, button, select, etc.), so if you added or changed any property
via JavaScript (apart from input.value) it won’t be reflected in the form. In
other words, browser does not send changed HTML document back as you may
think, it sends input information only. Asp.net engine parses this
information and updates compiled page that’s literally a wrapper around the
HTTP request (community guys - please forgive me for simplifying, Op seems to
lack this knowledge). If you want to know the value of the client side
variable / property use hidden input to store it – it’ll be then available on
the server side, or use AJAX asynchronous calls (more advanced).

Hope everything is clear now

Regards

Milosz

--
Milosz
"patrickdrd" wrote:
I've had the exact problem both in ASP.NET 1.1 and now I'm facing it in 2.0
as well!

Well, the case is this
(I'll mention the 1.1 case, which is easier to tell):

on a user input form (data entry - update a customer, let's say),
the user types the new data and presses the update button to commit the
changes,
however, javascript is called before the postback in order to validate the
input values,
if something goes wrong prompts the user to correct,
and, when everything is ok, posts the page to the server.

If I change a single value on a single field with javascript on this example
and then post back the page to the server, that change can't be seen by the
server,
while user values and changes of the fields can!

Why? How is that?

"Mark Rae" wrote:
"patrickdrd" <pa********@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...

Patrick,
Well, ok, forget about the page's source,
my mistake mentioning this,
It's a common misconception... :-)
my real problem is that the variable show its 'original' value when
submitted to the server and not the one that javascript changed to!
Why isn't that variable/field 'refreshed'?
Do I need to do something (like a 'refresh')?
This, however, is a different issue...

Client-side data changes, whether caused by user typing or JavaScript,
should certainly survive a postback.

You'll need to post your code...

Feb 1 '07 #12
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:56**********************************@microsof t.com...
radio button, button, select, etc.), so if you added or changed any
property
via JavaScript (apart from input.value) it won't be reflected in the form.
Yes but, unless I've completely misunderstood the OP, he's not talking about
client-side JavaScript changing properties of DOM element e.g. backcolor,
borderwidth etc...

I believe he's talking about changing the *value* of input controls via
JavaScript, and this most certainly *should* survive the postback...
Feb 1 '07 #13
Yes Mark, in this we need to see the code. I suspect he changes soemthing else.

Patrick show us the code ! :)
--
Milosz
"Mark Rae" wrote:
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:56**********************************@microsof t.com...
radio button, button, select, etc.), so if you added or changed any
property
via JavaScript (apart from input.value) it won't be reflected in the form.

Yes but, unless I've completely misunderstood the OP, he's not talking about
client-side JavaScript changing properties of DOM element e.g. backcolor,
borderwidth etc...

I believe he's talking about changing the *value* of input controls via
JavaScript, and this most certainly *should* survive the postback...
Feb 1 '07 #14
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:EB**********************************@microsof t.com...
Patrick show us the code ! :)
Maybe if a couple more people ask, he actually will... ;-)
Feb 1 '07 #15
Guys I'm having the exact same problems with this guy posted here:

http://www.dotnetjunkies.com/WebLog/...gory/1853.aspx

(look for: "JavaScript value modification problem")

and sorry for not being precise before.

So, can anyone help me with this?
Feb 16 '07 #16
hi there,

This is not longer a problem in asp.net 2.0. There's a special property of
button called OnClientClick:

<asp:Button runat="server" ID="btn"
OnClientClick="SetSomeHiddenFields();return true;" Text="Post Me!"/>

Regards
--
Milosz
"patrickdrd" wrote:
Guys I'm having the exact same problems with this guy posted here:

http://www.dotnetjunkies.com/WebLog/...gory/1853.aspx

(look for: "JavaScript value modification problem")

and sorry for not being precise before.

So, can anyone help me with this?
Feb 20 '07 #17
Well, I found exactly where the problem lies:

When the control that changes value is a web control!

Try yourselves the following code:
page:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false"
  2. CodeFile="test2.aspx.vb" Inherits="test2" %>
  3.  
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  5. <html>
  6. <head runat="server">
  7. <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div>
  12.  
  13. <asp:label ID="lblTotalQuantity" EnableViewState="true" runat="server"
  14. BackColor="ButtonFace" Width="50px"></asp:label>
  15.  
  16. <input type="text" runat="server" id="txtTest" />
  17. <input type="button"
  18. onclick="javascript:document.all['lblTotalQuantity'].innerHTML = '111';" />
  19.  
  20.  
  21. <input type="button" onclick="javascript:document.all['txtTest'].value
  22. = '111';" />
  23.  
  24. <input type="button" runat="server" id="btnTest" />
  25. </div>
  26. </form>
  27. </body>
  28. </html>
and code behind:
Expand|Select|Wrap|Line Numbers
  1. Partial Class test2
  2. Inherits System.Web.UI.Page
  3.  
  4. Private Sub MessageMake(ByVal strMessage As String)
  5.  
  6. 'Creates a messagebox with a message passed in
  7.  
  8. Response.Write(String.Format("<script
  9. language=javascript>alert('{0}')</script>", strMessage))
  10.  
  11. End Sub
  12.  
  13. Protected Sub btnTest_ServerClick(ByVal sender As Object, ByVal e As
  14. System.EventArgs) Handles btnTest.ServerClick
  15.  
  16. MessageMake(lblTotalQuantity.Text)
  17.  
  18. End Sub
  19. End Class
When I update that asp label control with javasript and try to get its value
after posting back, not only I don't get it (I get blank),
but loses its value and becomes blank as well!

Why?
Could someone please tell me why this is happening?

Should I use a span with runat="server"?

Thanks in advance!
Mar 23 '07 #18
the above result is the same, if I use a span with runat="server"!

So, how do I tell asp.net to remember those values set by javascript?
Mar 23 '07 #19
only <input>, <textareaand <selectvalues are posted back by the
browser. use a hiden field (<input type'hidden">)

-- bruce (sqlwork.com)
patrickdrd wrote:
the above result is the same, if I use a span with runat="server"!

So, how do I tell asp.net to remember those values set by javascript?
Mar 23 '07 #20
"patrickdrd" <pa********@discussions.microsoft.comwrote in message
news:36**********************************@microsof t.com...
the above result is the same, if I use a span with runat="server"!
That's right - these "label"-type fields are not posted back to the server,
because (I suppose) they do not permit data entry...
So, how do I tell asp.net to remember those values set by javascript?
Easiest method is to use a hidden field.
Mar 23 '07 #21
You mean, update the hidden field when updating the label (at the same time)?
Mar 23 '07 #22
"patrickdrd" <pa********@discussions.microsoft.comwrote in message
news:DD**********************************@microsof t.com...
You mean, update the hidden field when updating the label (at the same
time)?
Yes.
Mar 23 '07 #23
bruce and mark thank you very very much guys!

I'll try your (very useful ... I guess) suggestions!
Mar 23 '07 #24
It still not retains its value after postback!
Mar 28 '07 #25

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

Similar topics

3
2336
by: Srini | last post by:
I have a server side label and text box From the client side I am changing the value of the ASP.NET labe using the innerText property of the label. When I try to access the label from the server side I am getting the old valu of the label which was initially populated before calling the java script function . Can anyone tell me what is going...
1
1145
by: Jerry Camel | last post by:
1. I can add a value to a listbox, but when the page posts back, I lose the items I added from client side script. (Items added in server script stay in the list.) I'm guessing it's a view state issue or something. How do I add items to a listbox on the client side and have them acknowledged by the viewstate process? 2. Is it possible to...
4
3113
by: Guadala Harry | last post by:
Suppose I have a hyperlink that, when clicked, executes a JavaScript function on the client. Separately I have a button that, when clicked, causes a post back and executes a server-side function, as in the following: <a id="HyperLink5" href="javascript:DoSomethingInClient()">Do Something</a> <asp:Button id="btnSaveChanges"...
6
3842
by: Mike Chen | last post by:
We know in server code, we can check the page validated by using Page.IsValid where we put some validator controls on aspx page. I want to set some value after validating user input values on client side and before page posts to server. How can i get the functionality of client side Page.IsValid? thanks.
3
1180
by: sspost | last post by:
I have a web pages A and B , when i enter values in a number of textboxes in page A and click "Continue" button and go to page B, and click the browser's back button the page A is back as it was during page load initailly with no values in it I want to add a "Back" button in page B , which when clicked goes to page A and retains all the values...
0
1369
by: lvlacic | last post by:
Hi all, From my ASP.NET page, I need to print a Crystal Report to client's printer directly. I'm not using Crystal Report Viewer. I cannot use Crystal's PrintToPrinter method because this runs on Web Server side. How can I do this? Any help would be appriciated. I've seen a bunch of other posts with similar question, but I have not...
0
7182
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
7408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
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
7548
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
5714
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...
0
4773
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
3267
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...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
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.