帮助!
我有一个登录和一个注册html表单,每个表单都单击表单上的相应链接,并且没有回发或页面刷新事件。
问题是asp.net不允许我有两个runat = server表单。 我可以访问表单的输入字段。
我在表单中添加了 asp:Button 代替 输入类型=“提交” 为了访问onclick方法,但是再次asp.net不允许我添加asp按钮(服务器端控件)当我从任何具有此asp按钮的表单中删除runat =“server”时!
问题:
如何访问表单的提交按钮,以便我可以在注册和登录操作后执行必要的代码
有没有办法实现我的目标? (可能是某种方式隐藏其中一个表单开始并在我点击切换链接时显示它)
这是登录注册表单的
代码:
<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>
答案 0 :(得分:0)
好的,最后我在动脑筋后得到了它!
这就是我所做的:
在两个服务器端表单上应用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");
}
简而言之: 形式可见属性和会话变量的组合做了伎俩!!