Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 20th, 2013, 11:52 AM
Registered User
Points: 52, Level: 1
Points: 52, Level: 1 Points: 52, Level: 1 Points: 52, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Smile how I can extract the text of a Button?

hello I need to know how I can Extract the text of a Button and that event use it for many Buttons like A to Z
something like this

protected void btnText_Click(object sender, EventArgs e)
{
string Char= Button.Text.ToString(); //
Label1.Text = Char.ToString();
}

and on the aspx is like this

<asp:Button ID="btnA" runat="server" Text="A" onclick="btnText_Click" class="btn-mini"/>&nbsp; <!--this event is for use on all the buttons-->

<asp:Button ID="btnB" runat="server" Text="B" onclick="btnText_Click" class="btn-mini"/>&nbsp;

<asp:Button ID="btnC" runat="server" Text="C" onclick="btnText_Click" class="btn-mini"/>&nbsp;

thank you very much!

Last edited by light882; September 20th, 2013 at 11:55 AM.
  #2 (permalink)  
Old September 20th, 2013, 01:20 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Hi there,

You can cast the sender to a Button and use its Text like this:

string buttonText = (sender as Button).Text;

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
light882 (September 20th, 2013)
  #3 (permalink)  
Old September 20th, 2013, 02:12 PM
Registered User
Points: 52, Level: 1
Points: 52, Level: 1 Points: 52, Level: 1 Points: 52, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Talking YES IT DID!!!! THANK YOU!!!

thank you very mucho!!!! it was more simple than do:

Button clickedButton = (Button)sender;
if (btnA == clickedButton)
letra1 = "a";
if (btnB == clickedButton)
letra1 = "b";
if (btnD == clickedButton)
letra1 = "d";
if (btnE == clickedButton)
letra1 = "e";
if (btnF == clickedButton)
letra1 = "f";
if (btnG == clickedButton)
letra1 = "g";
if (btnH == clickedButton)
letra1 = "h";
if (btnI == clickedButton)
letra1 = "j";
if (btnK == clickedButton)
letra1 = "k";
if (btnL == clickedButton)
letra1 = "l";
if (btnM == clickedButton)
letra1 = "m";
if (btnO == clickedButton)
letra1 = "o";
if (btnP == clickedButton)
letra1 = "p";
if (btnQ == clickedButton)
letra1 = "q";
if (btnR == clickedButton)
letra1 = "r";
if (btnS == clickedButton)
letra1 = "s";
if (btnT == clickedButton)
letra1 = "t";
if (btnU == clickedButton)
letra1 = "u";
if (btnV == clickedButton)
letra1 = "v";
if (btnW == clickedButton)
letra1 = "w";
if (btnY == clickedButton)
letra1 = "y";
if (btnZ == clickedButton)
letra1 = "z";
Label1.Text = letra1;
  #4 (permalink)  
Old December 14th, 2015, 06:19 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Extract the text of a button!

Hi light882,
I also have a similar question and I've found my answer from this link
http://forums.asp.net/t/1019716.aspx...ield+GridView+

You can visit this link. may be helpful for you.

Thanks!!!!
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
extract data from one big text element JohnBampton XSLT 12 August 23rd, 2009 09:43 AM
how to extract text from html??? naureen Java Basics 2 October 2nd, 2007 12:19 PM
Extract text from webpages asif_sharif ASP.NET 2.0 Basics 7 October 1st, 2007 04:56 PM
Extract text with java script TheMajor Javascript 5 September 30th, 2007 10:45 PM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 10:49 PM



All times are GMT -4. The time now is 05:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.