Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2013, 10:52 AM
Registered User
 
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 10:55 AM..
 
Old September 20th, 2013, 12:20 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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)
 
Old September 20th, 2013, 01:12 PM
Registered User
 
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;
 
Old December 14th, 2015, 06:19 AM
Registered User
 
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!!!!





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.