We help IT Professionals succeed at work.
Get Started

Adding a login form to the header of an aspx file

John Carney
John Carney asked
Last Modified: 2012-05-06
Please take a look at this file: http://dijitalrealm.com/default2.aspx I'm new to asp.net and I want to put a login form in the upper right of the header.

I'm working with Visual Web Developer 2008 Express. I tried dragging a login control into design view, but when I previewed the page I got this error message: "Control 'Login1' of type 'Login' must be placed inside a form tag with runat=server."
How do I fix that?

I've attached the code below. Please insert the code for the login form where it belongs inside the header. It should be where <div id="searchBox"></div> is located.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JohnsFirstWebApp._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    #container{width:880px; height:560px; margin: auto; background:white}
    #header{width:880px; height:130px; background:url(images/DJRHeaderDots.png) #221642}
    #searchBox{width:140px; height:20px; background: white; border: 1px solid #333; float:right; margin:20px 20px; padding-left:10px}
    .formHolder{width:400px; clear:both; margin-bottom:10px}
    .label{width:110px; text-align:right; padding: 0 10px; float:left;}
    body {margin-top:0px; background:url(images/DjRbg.png) repeat-x #221642; font-family:"Gill Sans MT"; font-size:15px}
    #footer{margin:auto; width:880px; height:32px; background:url(images/DjRFooterBG880.png)  no-repeat}
    .contentBox1{width:400px; height:auto; padding:20px 0 0 0; margin:0 auto; margin-top: 10px; color:#221642; text-align:center; font-family:Gill Sans MT; font-size:16px; font-weight:bold; font-style:italic}
    .contentBox2{width:400px; height:auto; border:1px solid blue; padding:20px; margin:20px; color:green; font-family:Gill Sans MT; font-size:16px; font-weight:bold;}
    .contentBox3{width:auto; height:auto; padding:20px; margin:20px; font-family:Verdana; font-size:11px; margin: auto}
    <link rel="Shortcut Icon" href="images/DJRFavicon.ico" type="image/x-icon" />
<div id="container">
<div id="header">
<div id="searchBox"></div>
<div class="contentBox3">
 <div align="center">    
  <form id="form1" runat="server">
       <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:aardvark2ConnectionString %>" 
SelectCommand="SELECT [first], [last], [age], [address], [city], [state], [email] FROM fieldreps2 ORDER BY [first]">
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" 
            AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
            CellPadding="4" DataKeyNames="first" ForeColor="#333333" GridLines="None">
            <RowStyle BackColor="#EFF3FB" />
                <asp:CommandField ShowEditButton="False" />
                <asp:BoundField DataField="first" HeaderText="first" 
                    InsertVisible="False" ReadOnly="True" SortExpression="first" />
                <asp:BoundField DataField="last" HeaderText="last" SortExpression="last" />
                <asp:BoundField DataField="age" HeaderText="age" 
                    SortExpression="age" />
                <asp:BoundField DataField="address" HeaderText="address" 
                    SortExpression="address" />
                <asp:BoundField DataField="city" HeaderText="city" 
                    SortExpression="city" />
                <asp:BoundField DataField="state" HeaderText="state" SortExpression="state" />
                <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
       <br />
       <br />
     <div class="contentBox1">We're working on it ...</div>
<div id="footer"></div>

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE