开发者

improper act in web page

I have a web page that contain login control, I face a problem :

The code behind not matched to the design.For example , it gives me an error

Login1 cannot be found in the current context

And when I try to add event to the login it is written as the following:

<%@ Page Language="C#"  AutoEventWireup="true"  CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %>

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

<script runat="server">

    protected void LoginButton_Click(object sender, EventArgs e)
    {

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">

    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            height: 28px;
        }
    </style>
</head>
<body >
    <form id="form1" runat="server">
    Name retrieved from ViewState: <asp:Label runat="server" id="NameLabel" />
    <div>

    </div>
    <asp:Login ID="Login1" runat="server" onauthenticate="Login1_Authenticate">
        <LayoutTemplate>
            <table border="0" cellpadding="1" cellspacing="0" 
                style="border-collapse:collapse;">
                <tr>
                    <td>
                        <table border="0" cellpadding="0">
                            <tr>
                                <td align="center" colspan="2">
                                    Log In</td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User 
                                    Name:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                        ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                        ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                </td>
                        开发者_运维技巧        <td>
                                    <asp:TextBox ID="Password" runat="server" TextMode="Password" 
                                        ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                        ControlToValidate="Password" ErrorMessage="Password is required." 
                                        ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color:Red;">
                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2" class="style1">
                                    <asp:Button ID="LoginButton" runat="server" CommandName="Login" 
                                         Text="Log In" ValidationGroup="Login1" onclick="LoginButton_Click" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
    </asp:Login>
    </form>
</body>
</html>

Any idea to solve this problem , the big problem is that the code doesn't see the design and vise verse


Firstly :

Make sure that your name space is :

WebApplication4

and the class name is:

_Default

in your code behind file.like this:

namespace WebApplication4
{
    public partial class _Default : System.Web.UI.Page
    {
    }
}

secondly:

Make sure the consistency of the .aspx.designer.cs file.

I mean make sure that there is a reference of your control in this file .like this:

 protected global::System.Web.UI.WebControls.Login Login1;

and tell us which Visual studio version does u use.


It sounds like the designer.cs file is out of sync. If you go into the designer.cs file, you can declare the control, like this:

/// <summary>
/// Login1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Login Login1;

You might also try cutting and pasting the markup, so the designer registers all of the controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜