Results 1 to 10 of 10

Thread: Problem with asp.net pages

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Problem with asp.net pages

    Hi!!

    I am a pretty experienced C# programmer, and now the time has come for me to write web applications. I start a new project (web application) and add a button on the page

    PHP Code:
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication5.WebForm1" %>
    <!
    DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <
    HTML>
        <
    HEAD>
            <
    title>WebForm1</title>
            <
    meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
            <
    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">
                <
    asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 465px; POSITION: absolute; TOP: 139px" runat="server" Text="Button" Width="140px" Height="75px"></asp:Button>
            </
    form>
        </
    body>
    </
    HTML
    But the page is BLANK when I run the project!!!! Where is the button?

    The installation is verified.

    best regards
    Henrik

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Also, I looked at an example at Microsoft quickstart guides, and wrote this aspx file:

    PHP Code:
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ 
    Import Namespace="System.Data" %>
    <
    HTML>
        <
    HEAD>
            <
    script language="C#" runat="server">

           private 
    void SubmitBtn_Click(Object senderEventArgs e) {

              
    SqlConnection myConnection = new SqlConnection("server=4647117000n26;database=MVS;Trusted_Connection=yes");
              
    SqlDataAdapter myCommand = new SqlDataAdapter("select * from mvs_jobs"myConnection);

              
    DataSet ds = new DataSet();
              
    myCommand.Fill(ds"mvs_jobs");

              
    MyList.DataSource ds.Tables["mvs_jobs"].DefaultView;
              
    MyList.DataBind();
           }

            </
    script>
        </
    HEAD>
        <
    body>
            <
    center>
                <
    form action="intro8.aspx" method="post" runat="server" ID="Form1">
                    
                        
    Name:
                        <
    asp:textbox id="Name" runat="server" />
                        
    Category:
                        <
    asp:dropdownlist id="Category" runat="server">
                            <
    asp:listitem>psychology</asp:listitem>
                            <
    asp:listitem>business</asp:listitem>
                            <
    asp:listitem>popular_comp</asp:listitem>
                        </
    asp:dropdownlist>
                    </
    h3>
                    <
    asp:button text="Lookup" OnClick="SubmitBtn_Click" runat="server" ID="Button1" NAME="Button1" />
                    <
    p>
                        <
    ASP:DataGrid id="MyList" HeaderStyle-BackColor="#aaaadd" BackColor="#ccccff" runat="server" />
                </
    form>
            </
    center>
            </
    P>
        </
    body>
    </
    HTML

    In the design view, everything looks fine, in the HTML view it also looks good, but when I run the damned webpage, all I get is the TEXT output, no controls whatsoever.

    Can ANYONE help me with this???? When designing web applications, the first thing one can ask for is that the controls show up on the page...


    best regards
    Henrik

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    It is nothing you did wrong. It is a common problem when .NET is installed, it sometimes craps on IIS. Here is the fix:

    You need to run regiis.exe -i from
    c:\winnt\microsoft.net\framework\v1.0.3705 directory, where c:\winnt is the
    directory in which you installed the OS. Regiis.exe -i re-establishes the
    configuration suffixes in IIS used by .NET. You need to run it from the
    command line.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    YEAH, it solved my problem! Many thanks.


    One other thing I have thought about, where should I really write my C# code? For example, if a button click should generate a db call, should I write all that code in the cs file:

    PHP Code:
    private void Button1_Click(object senderSystem.EventArgs e)
            {
            
            } 
    or as a C# script within the aspx file?? I am a bit consfused

    best regards
    Henrik

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    either way. You can have all your C# code in a seperate c# file, then you can inherit that file from the aspx page, and have the class in your .cs file inherit the Page object. This technique allows complete seperation of your code and is a good thing to learn. You should do some research on it. The technique is called Code Behind.

    but until you learn that, it is perfectly fine to stick the code in the script tag area.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Member
    Join Date
    Nov 2002
    Posts
    32

    I definitely feel u shud use code-behind

    pls do use code-behind. this is an wonderful opportunity for us (microsoft web-developers) to separate design from code forever, an advantage which the java people have used so far.


    sujala

  7. #7
    Addicted Member
    Join Date
    Aug 2001
    Location
    New York
    Posts
    165
    Sujala, Cander,

    Interesting to see you both advocate the code behind method. Being a complete newbie to .NET, are there any particular advantages in terms of performance to using code behind? or does it mainly benefit organisation of code? (I am also researching this).

    Thanks, Chris

  8. #8
    Addicted Member
    Join Date
    Aug 2001
    Location
    New York
    Posts
    165
    Duplicate post...sorry...can somebody delete this?
    Last edited by csf; Nov 15th, 2002 at 01:31 PM.

  9. #9
    Lively Member
    Join Date
    Aug 2002
    Location
    outerspace
    Posts
    126
    one feature is better performance since it is already complied with the code behind it doesnt have to compile at runtime. And it is easier to manage your code and im sure there are others
    "All those who wonder are not lost" -j.r.r tolkien

  10. #10
    Addicted Member
    Join Date
    Aug 2001
    Location
    New York
    Posts
    165
    Interesting.

    Do you need Visual Studio .NET to create pre-compiled .NET apps or can you still create the code-behind file in Notepad and compile through the command line?

    Thanks.

Posting Permissions

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



Click Here to Expand Forum to Full Width