Value of Text property of the Button is kept at the server-side. And then
the control is rendered on the server, markup is generated and sent to the
client browser. So if you just change the markup in client browser, that
isn't signaled anyway to the server so it cannot change the text of what you
have sent from the client, unless you provide a mechanism to carry that
value from client to server (hidden field is one such). Note that you have
HTTP requests and responses going on this picture.
" protected void Button1_Click(Object sender, EventArgs e) {
this.Button1.Text = this.Button1.Text + "!"; }
I notice that the "!" gets added at every time so the text
on the button gets more and more exlamation marks"
This is essentially adding exclamation to the Text property at the server,
and then at the end of processing, it's rendered again to the browser. So it
is creating a illusion that you have state (or you do, but its created by
ASP.NET, HTTP itself is stateless)
With hidden field is meant that you have
<input type="hidden" ID="hidden1" runat="server" />
you set it's value in javascript and read it in Page_Load at the server for
example:
Button1.Text = hidden1.Value;
which should change the Button's text according to what you type to it (or
set with js)
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
K Viltersten said:
on post back of the page simply check your link's text
and re assign your text depanding on your desired value.
That's exactly what i'm doing (i think). The problem is that
the text i've assigned to the asp:LinkButton in the JS-code
is not there anymore!
this.dom.textContext = "beep";
The above does chenge the text of the button and i can
actually see that on the screen. However, when the page
is posted back and returned to the client, the old text
is there right back...
To be even more clear - the text i see changes as follows.
org -> beep -> org! -> beep -> org!! -> beep -> org!!!
I can't explain how the server knows what the previously
assigned text is but somehow it does. Suggestions?