未拾取 asp.net Web 用户控件文本框值 - jquery fancybox
我有一个包含两个表单的自定义 Web 控件。这些表单均包含一个用于提交表单的链接按钮。
当我尝试提交任一表单并追踪任何文本框的值时,这些值都是空的。如果我将“Text =“whatever””属性添加到文本框并重新测试,则会在跟踪测试中拾取并打印该值。
该控件是母版页的一部分,位于 之前。我假设它与回发序列有关,但现在已经研究了几个小时,并认为最好询问以前可能遇到过此问题的人。
控件的代码:
<div style="display: none;">
<div id="LoginRegisterModal" style="width:auto;height:360px;overflow:auto;">
<fieldset style="float:left; width:200px;">
<legend>Register</legend>
<p>Enter your email address below to register with us</p><br />
<div>
<asp:TextBox runat="server" ID="txtRegisterUsername" />
<br />
<asp:TextBox runat="server" ID="txtRegisterPassword" TextMode="Password" />
</div>
<asp:LinkButton Text="Register" runat="server" ID="btnRegister" OnCommand="btnLogin_Click" CommandArgument="Register" CssClass="registerButton" />
<br />
</fieldset>
<fieldset style="float:left; width:200px; margin-left:10px;">
<legend>Login</legend>
<p>Enter your email address below to login</p><br />
<div>
<asp:TextBox runat="server" ID="txtLoginUsername" />
<br />
<asp:TextBox runat="server" ID="txtLoginPassword" TextMode="Password" />
</div>
<asp:LinkButton Text="Login" runat="server" ID="btnLogin" CssClass="loginButton" OnCommand="btnLogin_Click" CommandArgument="Login" />
<br />
</fieldset>
<div style="clear:both; float:left;"></div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(".loginregister").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none'
});
});
</script>
背后的代码-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class includes_LoginRegister : System.Web.UI.UserControl
{
#region Load
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion
#region Events
protected void btnLogin_Click(object sender, CommandEventArgs e)
{
//Response.Redirect("our-team.aspx");
if (Common.HasValue(e.CommandArgument))
{
string strCommand = e.CommandArgument.ToString();
if (strCommand == "Login")
{
/**** Login ****/
string username = Membership.GetUserNameByEmail(this.txtLoginUsername.Text);
Trace.Warn("email address: " + this.txtLoginUsername.Text);
Trace.Warn("password: " + txtLoginPassword.Text);
Trace.Warn("username: " + username);
if (Common.HasValue(username))
{
MembershipUser mu = Membership.GetUser(username);
if (Common.HasValue(mu))
{
if (mu.IsApproved)
{
if (Membership.ValidateUser(username, this.txtLoginPassword.Text))
{
if (Roles.IsUserInRole(username, "Admin"))
{
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(username, false);
}
else
{
FormsAuthentication.SetAuthCookie(username, false);
Response.Redirect("~/cpanel/default.aspx");
}
}
else
{
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(username, false);
}
else
{
FormsAuthentication.SetAuthCookie(username, false);
Response.Redirect("~/member.aspx");
}
}
}
else
{
Trace.Warn("Incorrect email/password combo.");
//this.Page.Master.msgSiteMessageBox.ShowError("Incorrect email / password");
}
}
else
{
Trace.Warn("User not approved.");
//this.Page.Master.msgSiteMessageBox.ShowError("User not approved");
}
}
else
{
Trace.Warn("No such user exists.");
//this.Page.Master.msgSiteMessageBox.ShowError("No such user exists");
}
}
else
{
Trace.Warn("No such username from email.");
//this.Page.Master.msgSiteMessageBox.ShowError("No such username from email");
}
}
else
{
Trace.Warn("register email address: " + this.txtRegisterUsername.Text);
Trace.Warn("register password: " + txtRegisterPassword.Text);
try
{
/**** Register ****/
VantageDataContext dc = new VantageDataContext();
Candidate candidate = new Candidate();
int idCandidate = 0;
candidate.dtModified = DateTime.Now;
dc.Candidates.InsertOnSubmit(candidate);
candidate.dtCreated = DateTime.Now;
candidate.intStatus = 1;
candidate.chrEmail = txtRegisterUsername.Text.Trim();
dc.SubmitChanges();
MembershipUser mu = Membership.CreateUser("candidate-" + candidate.idCandidate.ToString(), txtRegisterPassword.Text, txtRegisterUsername.Text);
mu.IsApproved = true;
Membership.UpdateUser(mu);
Response.Redirect("~/member.aspx?new=true");
}
catch (Exception ex)
{
}
}
}
}
#endregion
}
I have a custom web control that contains two forms. These forms each contain a linkbutton to submit the form.
When I try to submit either form and trace out the values of any of the textboxes the values are empty. If I add a 'Text="whatever"' property to the textbox and re-test, the value is picked up and printed out in my trace test.
This control is part of a Masterpage and is sitting just before the </form>
. I am assuming it has something to do with postback sequence but have been playing around with it for a few hours now and thought it would be best to ask someone who may have run into this before.
The code for the control:
<div style="display: none;">
<div id="LoginRegisterModal" style="width:auto;height:360px;overflow:auto;">
<fieldset style="float:left; width:200px;">
<legend>Register</legend>
<p>Enter your email address below to register with us</p><br />
<div>
<asp:TextBox runat="server" ID="txtRegisterUsername" />
<br />
<asp:TextBox runat="server" ID="txtRegisterPassword" TextMode="Password" />
</div>
<asp:LinkButton Text="Register" runat="server" ID="btnRegister" OnCommand="btnLogin_Click" CommandArgument="Register" CssClass="registerButton" />
<br />
</fieldset>
<fieldset style="float:left; width:200px; margin-left:10px;">
<legend>Login</legend>
<p>Enter your email address below to login</p><br />
<div>
<asp:TextBox runat="server" ID="txtLoginUsername" />
<br />
<asp:TextBox runat="server" ID="txtLoginPassword" TextMode="Password" />
</div>
<asp:LinkButton Text="Login" runat="server" ID="btnLogin" CssClass="loginButton" OnCommand="btnLogin_Click" CommandArgument="Login" />
<br />
</fieldset>
<div style="clear:both; float:left;"></div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(".loginregister").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none'
});
});
</script>
The code behind -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class includes_LoginRegister : System.Web.UI.UserControl
{
#region Load
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion
#region Events
protected void btnLogin_Click(object sender, CommandEventArgs e)
{
//Response.Redirect("our-team.aspx");
if (Common.HasValue(e.CommandArgument))
{
string strCommand = e.CommandArgument.ToString();
if (strCommand == "Login")
{
/**** Login ****/
string username = Membership.GetUserNameByEmail(this.txtLoginUsername.Text);
Trace.Warn("email address: " + this.txtLoginUsername.Text);
Trace.Warn("password: " + txtLoginPassword.Text);
Trace.Warn("username: " + username);
if (Common.HasValue(username))
{
MembershipUser mu = Membership.GetUser(username);
if (Common.HasValue(mu))
{
if (mu.IsApproved)
{
if (Membership.ValidateUser(username, this.txtLoginPassword.Text))
{
if (Roles.IsUserInRole(username, "Admin"))
{
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(username, false);
}
else
{
FormsAuthentication.SetAuthCookie(username, false);
Response.Redirect("~/cpanel/default.aspx");
}
}
else
{
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(username, false);
}
else
{
FormsAuthentication.SetAuthCookie(username, false);
Response.Redirect("~/member.aspx");
}
}
}
else
{
Trace.Warn("Incorrect email/password combo.");
//this.Page.Master.msgSiteMessageBox.ShowError("Incorrect email / password");
}
}
else
{
Trace.Warn("User not approved.");
//this.Page.Master.msgSiteMessageBox.ShowError("User not approved");
}
}
else
{
Trace.Warn("No such user exists.");
//this.Page.Master.msgSiteMessageBox.ShowError("No such user exists");
}
}
else
{
Trace.Warn("No such username from email.");
//this.Page.Master.msgSiteMessageBox.ShowError("No such username from email");
}
}
else
{
Trace.Warn("register email address: " + this.txtRegisterUsername.Text);
Trace.Warn("register password: " + txtRegisterPassword.Text);
try
{
/**** Register ****/
VantageDataContext dc = new VantageDataContext();
Candidate candidate = new Candidate();
int idCandidate = 0;
candidate.dtModified = DateTime.Now;
dc.Candidates.InsertOnSubmit(candidate);
candidate.dtCreated = DateTime.Now;
candidate.intStatus = 1;
candidate.chrEmail = txtRegisterUsername.Text.Trim();
dc.SubmitChanges();
MembershipUser mu = Membership.CreateUser("candidate-" + candidate.idCandidate.ToString(), txtRegisterPassword.Text, txtRegisterUsername.Text);
mu.IsApproved = true;
Membership.UpdateUser(mu);
Response.Redirect("~/member.aspx?new=true");
}
catch (Exception ex)
{
}
}
}
}
#endregion
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论