网页中的不当行为

发布于 2024-12-06 09:18:40 字数 4709 浏览 0 评论 0原文

我有一个包含登录控件的网页,我面临一个问题:

后面的代码与设计不匹配。例如,它给了我一个错误

在当前上下文中找不到Login1

当我尝试向登录添加事件时,它的写法如下:

<%@ 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>

任何解决此问题的想法,最大的问题是代码看不到设计和虎钳诗句

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国产ˉ祖宗 2024-12-13 09:18:40

首先:

确保

WebApplication4

名称空间是: ,类名是:。

_Default

你的代码隐藏文件中的

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

像这样:其次:

确保.aspx.designer.cs文件的一致性。

我的意思是确保此文件中有您的控件的引用。就像这样:

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

并告诉我们您使用哪个 Visual Studio 版本。

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.

虚拟世界 2024-12-13 09:18:40

听起来 designer.cs 文件不同步。如果您进入 designer.cs 文件,您可以声明该控件,如下所示:

/// <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;

您还可以尝试剪切和粘贴标记,以便设计器注册所有控件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文