解一个就给分!
问题1:
signin.aspx中几个控件:
<asp:textbox runat="server" ID="UserName"/>
<asp:textbox runat="server" id="Password" textmode="Password"/>
<asp:Button ID="Button1" runat="server" Text="Login" OnClick="Button1_Click" />
在signin.aspx.cs里面:
public partial class SignIn : System.Web.UI.Page
{
    public void Button1_Click(object sender, EventArgs e)
    {
        string user = UserName.Text;
        string password = Password.Text;
        if (FormsAuthentication.Authenticate(user, Password))
        {
      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(user, false, 5000);
            FormsAuthentication.RedirectFromLoginPage(user, true);
        }
    }
}
编译提示:
1 “SignIn.Button1_Click(object, System.EventArgs)”不可访问,因为它受保护级别限制
2  CS0103: 当前上下文中不存在名称“UserName”
3  CS0103: 当前上下文中不存在名称“Password”
把它放在aspx文件的script部分还是有2和3提示,点解?问题2:
target的目标一定只能放在frame或window里面吗?我想定位到一个contentplaceholder里面可以吗?
但总是会跳出一个新窗口显示,而不是出现在id=contentplaceholder1的控件里面!点解?

解决方案 »

  1.   

    1.没有声明控件,你可添加如下
    protected System.Web.UI.WebControls.TextBox UserName;
    protected System.Web.UI.WebControls.TextBox Password;
    2.不可以,用户控件虽然是控件,但与FRAME等不同,target属性不可用.
      

  2.   

    1.没有声明控件,你可添加如下
    protected System.Web.UI.WebControls.TextBox UserName;
    protected System.Web.UI.WebControls.TextBox Password;
    2.不可以,用户控件虽然是控件,但与FRAME等不同,target属性不可用.
    ==========
    同上
      

  3.   

    感谢hchxxzx
    可是asp.net2.0不是不需要声明控件了吗,那不是asp1.x里面的事情吗?
      

  4.   

    不是都用partial 关键字了吗,还需要申明控件?
      

  5.   

    老大压,你是不是用微软自带的Login控件呀,那当然找不到拉
    因为写法就错了,根本不用找到就可以用的,如果你非要找,那么你肯定是转成模板了,那么要用FindControl拉
      

  6.   

    TextBox tb1 = (TextBox)Login1.FindControl("UserName");
            TextBox tb2 = (TextBox)Login1.FindControl("Password");
            string name = tb1.Text;
            string pwd = tb2.Text;
            if (Membership.ValidateUser(name, pwd))
            {
                FormsAuthentication.SetAuthCookie(name, false);
                if (Roles.IsUserInRole(name,"adminGroup"))
                {
                      ////////////////
                }
                else
                {
                    ////////////////////////
                }
            }
    但愿我猜的没有错
      

  7.   

    artak(甜葡萄)大哥说的一点不差,是Login控件用了<LayoutTemplate> 能说说怎么处理吗,给个小例子,小弟跪下了!
      

  8.   

    1 “SignIn.Button1_Click(object, System.EventArgs)”不可访问,因为它受保护级别限制
    还是存在啊!为什么?
      

  9.   

    将OnClick="Button1_Click"去掉,双击button,在cs文件在粘贴代码
      

  10.   

    还有点问题,再帮下小弟。cs文件里findcontrol找到的是null?
    aspx里面层次为:
    <body>
    <form runat="server" id="form1">
    <asp:LoginView ID="loginArea" runat="server">
    <AnonymousTemplate>
    <asp:Login ID="login1" runat="server">
    <LayoutTemplate>
    <table>
    <asp:textbox runat="server" ID="UserName">
    <asp:textbox runat="server" id="Password">
    </table>