Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

Change the text on an aspx button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
K Viltersten - 18 May 2008 16:06 GMT
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
Teemu Keiski - 18 May 2008 21:16 GMT
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)

Signature

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

>I have the following button:
> <asp:LinkButton id="Btn" runat="server" text="Click">
[quoted text clipped - 15 lines]
> sleep    - a substitute for coffee for the poor
> ambition - lack of sense to be lazy
K Viltersten - 19 May 2008 06:40 GMT
> 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
Munna - 19 May 2008 07:22 GMT
> > you should change the text on the server as controls aregenerated from
> > the server to the client. Therefore youshould ignal to the server that
[quoted text clipped - 23 lines]
> 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
K Viltersten - 19 May 2008 08:35 GMT
>>    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
Teemu Keiski - 19 May 2008 20:36 GMT
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)

Signature

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

>>    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
K Viltersten - 19 May 2008 21:27 GMT
> Value of Text property of the Button is kept at the
> server-side. And then  the control is rendered on the
[quoted text clipped - 16 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.