Beginner needs help -- Simple AspNet Component

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim H

    Beginner needs help -- Simple AspNet Component

    I coded my first asp form and attempted to display a text message from a component. The static text "Our component
    says:" shows on the aspx page, but the text line from the component does not show. No errors are produced.

    Can someone get me started down the right path with aspnet?

    The two modules are shown below. The solution, less the .dll and .pdb files, can ge grabed at
    http://psiprograms.com/Programs/HelloWorld.zip (about 16 Kb).

    Thanks, Jim Holloman


    ----aspx page-------------------------------------------------------------------
    <%@ Import Namespace="Hell oWorldApp" %>
    <%@ Page language="c#" Codebehind="Web Form1.aspx.cs" AutoEventWireup ="false" Inherits="Hello WorldApp.WebFor m1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1 </title>
    <meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
    <meta name="CODE_LANG UAGE" Content="C#">
    <meta name="vs_defaul tClientScript" content="JavaSc ript">
    <meta name="vs_target Schema" content="http://schemas.microso ft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING= "GridLayout ">
    <form id="Form1" method="post" runat="server">
    Our component says: &lt; br /&gt; &lt; br /&gt;
    <asp:Label ID="Labe11" runat="server"> </asp:Label>

    <!-- Putting the code within the "form" creates a server error indicating that Page_Load()
    is already defined -->
    <!--
    <script language="C#" runat="server">
    void Page_Load( Object sender, EventArgs e )
    {
    HelloWorld oHelloWorld = new HelloWorld();
    Labe11.Text = oHelloWorld.Say Hello();
    }
    </script>
    -->

    </form>

    <!-- This code apparently does nothing! -->
    <script language="C#" runat="server">
    void Page_Load( Object sender, EventArgs e )
    {
    HelloWorld oHelloWorld = new HelloWorld();
    Labe11.Text = oHelloWorld.Say Hello();
    }
    </script>

    </body>
    </HTML>


    ----Hello World component-------------------------------------------------------
    using System;

    namespace HelloWorldApp
    {
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class HelloWorld
    {
    public HelloWorld()
    {
    // TODO: Add constructor logic here
    }

    public string SayHello()
    {
    return "Hello World -- form a C# component developed with the Visual Studio IDE \n\n";
    }
    }
    }
  • Natty Gur

    #2
    Re: Beginner needs help -- Simple AspNet Component

    Hi,
    [color=blue]
    >Putting the code within the "form" creates a server error >indicating[/color]
    that Page_Load()

    You have two ways that you can write your server code : using code
    behind (personally, i prefer it) or embedding the code in the ASPX file
    (as you do) but you cant do them both.

    Remove the code that attach the page load event (this.Load +=
    EventHandler(Pa ge_load)) and you wont get the above error. Or write
    server side code in the code behind.

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    Working...