Beginner needs help -- Simple AspNet Component

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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
    [url]http://psiprograms.com/Programs/HelloWorld.zip[/url] (about 16 Kb).

    Thanks, Jim Holloman


    ----aspx page-------------------------------------------------------------------
    <%@ Import Namespace="HelloWorldApp" %>
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="HelloWorldApp.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.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.SayHello();
    }
    </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.SayHello();
    }
    </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";
    }
    }
    }
    Jim H Guest

  2. Similar Questions and Discussions

    1. Simple Question From Beginner
      I have created an swf movie, which I embedded to my site. I want my movie to play only once , just when the mouse cursor hovers over this movie...
    2. Serviced Component runs under ASPNET, not specified account
      Cross posting since I had no reply yet from microsoft.public.dotnet.framework.component_services Hi all, I have an ASP.NET app and a Serviced...
    3. Restricting ASPNET ACLs without breaking ASPNET (newbie-ish)
      Scenario: We have a library with objects that host Jscript for the execution of complex validation code. This library is being called by an ASP.NET...
    4. Beginner - two simple questions please?
      Hello, This is my first post so hello to everyone. I have two questions that I have been struggling with. I am using release 2.5.1 1. I...
    5. Suggestion: POE::Component::IRC::Simple
      Hello, I have just written my first bot. I was recommended using POE::Component::IRC and I must admit it was a a good recommendationB. I have...
  3. #2

    Default Re: Beginner needs help -- Simple AspNet Component

    Hi,
    >Putting the code within the "form" creates a server error >indicating
    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(Page_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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139