asp.net web用户控件文本框值未被拾取 - jquery fancybox

时间:2011-10-13 08:33:49

标签: c# jquery asp.net asp.net-membership fancybox

我有一个包含两个表单的自定义Web控件。这些表单每个都包含一个链接按钮来提交表单。

当我尝试提交任一表单并跟踪任何文本框的值时,值为空。如果我在文本框中添加'Text =“无论”'属性并重新测试,则会在我的跟踪测试中拾取并打印出该值。

此控件是母版页的一部分,位于</form>之前。我假设它与回发序列有关,但现在已经玩了几个小时了,并且认为最好先问一下可能遇到此问题的人。

控件的代码:

<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
}

0 个答案:

没有答案