解一个就给分!
问题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:
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的控件里面!点解?
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.TextBox Password;
2.不可以,用户控件虽然是控件,但与FRAME等不同,target属性不可用.
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.TextBox Password;
2.不可以,用户控件虽然是控件,但与FRAME等不同,target属性不可用.
==========
同上
可是asp.net2.0不是不需要声明控件了吗,那不是asp1.x里面的事情吗?
因为写法就错了,根本不用找到就可以用的,如果你非要找,那么你肯定是转成模板了,那么要用FindControl拉
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
{
////////////////////////
}
}
但愿我猜的没有错
还是存在啊!为什么?
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>