By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,686 Members | 1,648 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

Change the text on an aspx button

P: n/a
I have the following button:
<asp:LinkButton id="Btn" runat="server" text="Click">
</asp:LinkButton>

I have added an action listener in the javascript
where I change the text on it:
this.dom.textContent = "Clicked";

The change is effective but after the site has
reloaded the text is back to "Click".

How can I make the change sustain? Should I use
something else than dom.textContent?

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello,

you should change the text on the server as controls are generated from the
server to the client. Therefore you should ignal to the server that it
should change text to what you need in this scenario (post it to the server
for example with a hidden form field)

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"K Viltersten" <tm**@viltersten.comwrote in message
news:69*************@mid.individual.net...
>I have the following button:
<asp:LinkButton id="Btn" runat="server" text="Click">
</asp:LinkButton>

I have added an action listener in the javascript where I change the text
on it:
this.dom.textContent = "Clicked";

The change is effective but after the site has reloaded the text is back
to "Click".
How can I make the change sustain? Should I use something else than
dom.textContent?

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #2

P: n/a
you should change the text on the server as controls aregenerated from
the server to the client. Therefore youshould ignal to the server that
it should change text towhat you need in this scenario (post it to the
server
for example with a hidden form field)
Perhaps i'm doing it a strange way. I'm changing the text
of the LinkButton using JavaScript on the client and as i
post it back, i try to read the text using the following.

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. Still,
i figure it should be possible to change the original text
of the button to something else and then send it back to
server. For some reason, the server only remembers the
text sent out at previous attempt.

And just to be perfectly clear - i can use a button as such
a field, right? Or are we taking about a specialized, hidden
componenet here?

--
Regards
Konrad Viltersten
Jun 27 '08 #3

P: n/a
On May 19, 11:40 am, "K Viltersten" <t...@viltersten.comwrote:
you should change the text on the server as controls aregenerated from
the server to the client. Therefore youshould ignal to the server that
it should change text towhat you need in this scenario (post it to the
server
for example with a hidden form field)

Perhaps i'm doing it a strange way. I'm changing the text
of the LinkButton using JavaScript on the client and as i
post it back, i try to read the text using the following.

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. Still,
i figure it should be possible to change the original text
of the button to something else and then send it back to
server. For some reason, the server only remembers the
text sent out at previous attempt.

And just to be perfectly clear - i can use a button as such
a field, right? Or are we taking about a specialized, hidden
componenet here?

--
Regards
Konrad Viltersten
Hi

on post back of the page simply check your link's text
and re assign your text depanding on your desired value.

you can take a hidden field in your page mark it as runat server.
in javascript when you change the text of the link mark the hidden
input to know that links text is chnage
when page post back .. grap the value of the hidden field and then
depending on value modify your links
text.
Thanks
Munna
www.munna.shatkotha.com
www.shatkotha.com
Jun 27 '08 #4

P: n/a
> protected void Button1_Click(Object sender, EventArgs e) {
> this.Button1.Text = this.Button1.Text + "!"; }
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?

--
Regards
Konrad Viltersten
Jun 27 '08 #5

P: n/a
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" <tm**@viltersten.comwrote in message
news:op***************@lp028.pagero.local...
> protected void Button1_Click(Object sender, EventArgs e) {
this.Button1.Text = this.Button1.Text + "!"; }
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?

--
Regards
Konrad Viltersten
Jun 27 '08 #6

P: n/a
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.

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)
Right now, i could kiss you. (Good thing you're
far away in Finland, hehe.)

Great thanks!

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.