asp.net 中的多个 runat 服务器表单

multiple runat server forms in asp.net

求助!

我有一个登录和一个注册 html 表单,每次单击表单本身上的相应 link 时都会切换,并且没有回发或页面刷新事件。

问题是 asp.net 不允许我有两个 runat=server 表单。 我可以访问表单的输入字段。

我添加了 asp:Button 代替 输入类型="submit" 在表单中以访问 onclick 方法,但是 asp.net 又不允许我添加 asp 按钮(服务器端控件) 当我从任何具有此 asp 按钮的表单中删除 runat="server" 时!

问题:

如何访问表单的提交按钮,以便在注册和登录操作后执行必要的代码

有没有办法实现我的目标? (可能是在开始时隐藏其中一种形式并在我单击切换时显示它的某种方式 link )

这是登录注册表单

代码:

<div>
<header>

        </header>
        <section>               
            <div id="container_demo" >

                <a class="hiddenanchor" id="toregister"></a>
                <a class="hiddenanchor" id="tologin"></a>
                <div id="wrapper">
                    <div id="login" class="animate form">
                        <form id="form1"  action="#" runat="server" > 
                            <h1>Log in</h1> 
                            <p> 
                                <label for="username" class="uname" data-icon="u" > Your email </label>
                                <input id="username" name="username" runat="server" required="required" type="text" placeholder="myusername or mymail@mail.com"/>
                            </p>
                            <p> 
                                <label for="password" class="youpasswd" data-icon="p"> Your password </label>
                                <input id="password" name="password" runat="server" required="required" type="password" placeholder="eg. X8df!90EO" /> 
                            </p>
                            <p class="keeplogin"> 
                                <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
                                <label for="loginkeeping">Keep me logged in</label>
                            </p>
                            <p class="login button">
                                <asp:Button Text="Submit" runat="server" OnClick="Submit" /> 
                                <!--<input type="submit" value="Login" />--> 
                            </p>
                            <p class="change_link">
                                Not a member yet ?

                                <a href="#toregister" class="to_register">Join us</a>             //toggle link
                            </p>
                        </form>
                    </div>

                    <div id="register" class="animate form">
                        <form id="form2" action="#" runat="server" > 
                            <h1> Sign up </h1> 
                            <p style="margin-top:4px;margin-bottom:2px;"> 
                                <label for="usernamesignup" class="uname" data-icon="u">Your username</label>
                                <input id="usernamesignup" name="usernamesignup" runat="server" required="required" type="text" placeholder="mysuperusername690" />
                            </p>
                            <p style="margin-top:4px;margin-bottom:2px;"> 
                                <label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
                                <input id="emailsignup" name="emailsignup" runat="server"  required="required" type="email" placeholder="mysupermail@mail.com"/> 
                            </p>
                            <p style="margin-top:4px;margin-bottom:2px;"> 
                                <label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
                                <input id="passwordsignup" name="passwordsignup" runat="server" required="required" type="password" placeholder="eg. X8df!90EO"/>
                            </p>
                             <p style="margin-top:4px;margin-bottom:2px;"> 
                                <label for="mob1" class="uname" data-icon="u">Your mob no.</label>
                                <input id="mob" name="mob" runat="server" required="required" type="text" placeholder="9450.." />
                            </p>

                            <p class="signin button"> 
                                 <asp:Button Text="Submit" runat="server" OnClick="Submitr" />
                                <!--<input type="submit" value="Sign up"/> -->
                            </p>
                            <p class="change_link">  
                                Already a member ?
                                <a href="#tologin" class="to_register"> Go and log in </a>          //toggle link
                            </p>
                </form>
                    </div>

                </div>
            </div>  
        </section>





</div>

好吧,我绞尽脑汁终于搞定了!

这就是我所做的:

在两个服务器端表单上应用了 asp 按钮

注册表单上:

<asp:Button Text="tologin" runat="server" OnClick="changetologin" ForeColor="#1DA2C1" BackColor="#F7F8F1" /> 

在登录表单上:

<asp:Button Text="Join us"  runat="server" OnClick="changetosignup" ForeColor="#1DA2C1" BackColor="#F7F8F1" />

页面加载:

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["form2"] == null && Session["form1"] == null) //show login hide signup
    {
        form1.Visible = true;
        form2.Visible = false; 

    }


    if (Session["form2"] != null && Session["form1"]==null ) //show signup hide login
    {
        form1.Visible = false;
        form2.Visible = true;
        Session["form2"] = null;
    }
    if (Session["form1"] != null && Session["form2"] == null)     //show login hide signup
    {
        form1.Visible = true;
        form2.Visible = false;
        Session["form1"] = null;
    }

}

点击切换按钮在注册表单上:

protected void changetologin(object sender, EventArgs e)
{

    Session["form1"] = "clicked";

    Response.Redirect("#tologin");

}

点击切换按钮在登录表单上:

 protected void changetosignup(object sender, EventArgs e)
{
    Session["form2"] = "clicked";

     Response.Redirect("#toregister");


}

简而言之: 表单可见 属性 和会话变量的组合成功了!!