Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird Problem

Status
Not open for further replies.

lilboi

Programmer
Dec 22, 2003
146
CA
Hey guys,

I basically just started on ASP.NET. I'm following this tutorial, word for word, and for some reason can't get the result it wants.

It's suppose to be a form that'll postback on itself. But when I click submit, it doesn't do anything after. It returns a blank page.

The tutorial said to leave 'action="HelloThere"' out and even if i put it in, the same result. What could it be?

Thanks!

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

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

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head>
    <title>Default Page</title>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                NameForm.Visible = false;
                NameLabel.Text = NameBox.Text;
                NameLabel.Style.Add("font-weight", "bold");
            }
            TimeLabel.Text = DateTime.Now.ToString();
        }
        
        </script>
</head>
<body>
<form id="NameForm" runat="server">
    <p>
        Hello <asp:Label ID="NameLabel" runat="server">There!</asp:Label></p>
    <p>
        <asp:TextBox ID="NameBox" runat="server"></asp:TextBox>
        <input type="submit" value="Submit" />
    </p>
    <div>
        The time is now: <asp:Label ID="TimeLabel" runat="server" Text="Label"></asp:Label>&nbsp;</div>
    </form>
</body>
</html>
 
Since you are just starting, now is a good time to get into good habits so I'd suggest starting by using a code behind page. This will make problems like this much easier to debug so you will be able to find out for yourself why it isn't working.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
your trying to use an html control to access asp.net code. that doesn't work.
this
Code:
<input type="submit" value="Submit" />
should be
Code:
<asp:Button id="MyButton" runat="server" OnClick="MyButton_Click" text="Submit Form" />
with this in the code behind
Code:
protected void Page_Load(object sender, EventArgs e)
{
   TimeLabel.Text = DateTime.Now.ToString();
}
protected void MyButton_Click(object sender, EventArgs e)
{
   NameLabel.Text = NameBox.Text;
   NameText.Text = "";
}
Not sure where you found this example/tutorial, but it's pathetic. I would keep searching for a better one. problems i see:
1. no code behind (mentioned by mark)
2. using Attributes to define style instead of ASP.Net control styles.
3. poor placement of code to execute.

And why is it hiding the form? that's where your final output is located.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Haha thanks so much guys!

Not sure where you found this example/tutorial, but it's pathetic.

hahaha time to do more search!


2. using Attributes to define style instead of ASP.Net control styles.

Can you elaborate on this one? I'm not sure what you mean by this...
 
instead of [tt]NameLabel.Style.Add("font-weight", "bold");[/tt]
use either CSS or the strongly typed property associated with the Control [tt]NameLabel.Font.Bold = true;[/tt]

CSS is stongly recommended. this seperates how your page works and how your page looks. forum215 is a great resource for that.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
jmeckley, i see what you mean.

I thought the NameLabel.Style.Add is somewhat like adding CSS to the control.

The thing is, I don't know css that much yet. But thanks for the suggestion. First .Net then CSS then the world!!! buahahahah! hehe j/k.

Thanks man!
 
yeah, css is my nemisis as well. fortunately my apps are inner company apps. they just have to be functional, not pretty:)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
jmeckley, oh the horror!

I'm already pretty bad at designing html and putting 'em in tables and now, I just found out that webpages in tables are out! The new thing is tableless CSS websites!! Horrible!! haha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top