Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 6
There are 1 users currently browsing forums.
Articles, Tutorials, and Guides Here is a collection of tutorials. You may submit tutorials and read them as you please.

Reply
  #1  
Old 04-20-2006
Mitch's Avatar
Emo Pose >.>
 
Join Date: Dec 2004
Location: United Kingdom
Age: 21
Posts: 2,757
Rep Power: 9
Mitch will become famous soon enoughMitch will become famous soon enough
[ASP.NET 2.0] Using Buttons! with C#

Please read this if you're just starting ASP.NET: Hello World!

Last time, I showed you an event handler for on Page Load, well now I'm going to show you how to do soemthing for on button click!

Get your aspx started:
Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <title>Buttons!</title>
</head>
<body>
<form runat="server">

</form>
</body>
</html>
Ok Now let's set up a textbox, label and button:
Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <title>Buttons!</title>
</head>
<body>
<form runat="server">
<asp:TextBox id="text1" runat="server" />
<asp:Button id="button1" onclick="calculate_Click" runat="server" />
<asp:Label id="label1" runat="server" />
</form>
</body>
</html>
Notice the "onclick="", this is going to be a key feature here, it will be the name of the method we are about to put in between the head tags.

Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <title>Buttons!</title>
    <script runat="server">
        void calculate_Click (object sender, EventArgs e)
        {
            label1.Text = "Hello, "+text1.Text+".";
        }
    </script>
</head>
<body>
<form id="Form1" runat="server">
Name: <asp:TextBox id="text1" runat="server" />
<asp:Button id="button1" text="Enter" onclick="calculate_Click" runat="server" />
<br />
<span style="font-size: 12px; font-family:verdana;"><asp:Label id="label1" runat="server" /></span>
</form>
</body>
</html>
There, we took the text from the textbox, and put it in the label.

Well there's buttons from the basics for you!
__________________
MitchStanley.co.uk - Coming Soon

Last edited by Mitch; 04-20-2006 at 07:35 PM.
Reply With Quote
  #2  
Old 04-20-2006
Master
 
Join Date: Oct 2004
Age: 18
Posts: 2,141
Rep Power: 8
Reaper is on a distinguished road
Re: [ASP.NET 2.0] Using Buttons! with C#

Weeee thanks. I'm goofing around and added a thing that says Enter a Name, if the text box is empty. Thanks for the intro. I'll look more into this.
Reply With Quote
  #3  
Old 04-20-2006
Mitch's Avatar
Emo Pose >.>
 
Join Date: Dec 2004
Location: United Kingdom
Age: 21
Posts: 2,757
Rep Power: 9
Mitch will become famous soon enoughMitch will become famous soon enough
Re: [ASP.NET 2.0] Using Buttons! with C#

No problem!

I tried using
if (text1.Text == "") {}
but no such luck, I remember it saying something about converting to a string/int or something , I'll have to look into it..

I'm also trying to find out how to delete a control or alteast hide it off the screen as you don't need the textbox there again after you have a valid name entered do you?

The closest I've got is text1.Enabled = false;

which disables it's usage, but doesn't hide it.
Reply With Quote
  #4  
Old 04-20-2006
Master
 
Join Date: Oct 2004
Age: 18
Posts: 2,141
Rep Power: 8
Reaper is on a distinguished road
Re: [ASP.NET 2.0] Using Buttons! with C#

Hmm. I'll look into this. Also, I use if(text1.Text == "" && text1.Text == " ") {}. How would I do it if the whole textbox was empty not just empty or 1 space?

Last edited by Reaper; 04-20-2006 at 08:17 PM.
Reply With Quote
  #5  
Old 04-20-2006
Mitch's Avatar
Emo Pose >.>
 
Join Date: Dec 2004
Location: United Kingdom
Age: 21
Posts: 2,757
Rep Power: 9
Mitch will become famous soon enoughMitch will become famous soon enough
Re: [ASP.NET 2.0] Using Buttons! with C#

If only we could use the trim function from PHP .
Reply With Quote
  #6  
Old 04-20-2006
Master
 
Join Date: Oct 2004
Age: 18
Posts: 2,141
Rep Power: 8
Reaper is on a distinguished road
Re: [ASP.NET 2.0] Using Buttons! with C#

Yeah, I agree .
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Google Spider Flash Buttons??? Makaveli Site Reviews & Site Management 5 03-21-2006 08:22 AM
Linux 2.6 and mouse wheels / side buttons _jameshales Unix/Linux/BSD 2 02-05-2006 12:02 AM
Getting Mouse Wheel and Side Buttons to Work in X.org/XFree _jameshales Articles, Tutorials, and Guides 0 01-01-2006 08:23 PM
Help with Writing a VBA quiz in Powerpoint itsallpsych Visual Basic Programming 12 08-01-2005 11:37 PM