每页绕过ASP.NET的一个RUNAT SERVER FORM [英] Bypassing ASP.NET's One RUNAT SERVER FORM per page

查看:209
本文介绍了每页绕过ASP.NET的一个RUNAT SERVER FORM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET限制使用多于1 runat =server表单。

我有一个<



我有很多其他页面,其中一些带有一个表单(Register.aspx - Login.aspx),一些没有表单。



我想在主用户中添加注销按钮(用户登录后)。



这是正常的,注销按钮应该始终存在。



但要使用这个 ASP按钮控制器我需要在主页面中使用一个表格

意思是,我不会能够访问具有表单的其他页面,因为我将收到一个错误消息。



我已经有其他想法可以绕过这个。



1-使用 JQuery 使用 Ajax 加载处理程序,清除会话。



2-使注销成为链接,看起来像一个按钮,点击它加载另一个 .aspx页面,在页面加载方法中,清除会话,然后重定向,听起来像第一个...



3-使它成为一个链接,它将我带到同一页面(Default.aspx?logout = 1)<并在页面加载方法内检查此参数,如果它存在,清除会议。



这些好方法吗?有什么更好的?

解决方案

你不需要绕过它,只需包装整个 asp :ContentPlaceHolder 表单runat =server中,这样你就可以在每一页上都有表单了。



在母版页中

 < form runat =server> 
< asp:ContentPlaceHolder id =MainBodyContent>< / asp:ContentPlaceHolder>
< / form>


ASP.NET restricts using more than 1 runat="server" form.

I have a Master Page, currently with no form.

I have many other pages, some with a form (Register.aspx - Login.aspx), some without a form.

I would like to add a Logout button in the master (After a user has logged in).

This is kind of normal, the Logout button should always be there.

But to use this ASP Button Controller I need to use a form in the Master Page.

Means, I will not be able to access other pages that has forms because I will receive an error.

I already have other ideas to bypass this.

1- Using JQuery to Load a Handler using Ajax, clear the Session.

2- Make the Logout a link which looks like a button, click on it to load another .aspx page, in the Page Load method, clear the Session, then redirect, sounds like the first one...

3- Make it a link which takes me to the same page (Default.aspx?logout=1) <- and check this parameter inside the Page Load method, if it's there, clear the Session.

Are these good approaches? is there any better?

解决方案

You don't need to bypass it, just wrap the entire asp:ContentPlaceHolder inside the form runat="server" so you'll have the form on every page already.

In the master page

<form runat="server">
    <asp:ContentPlaceHolder id="MainBodyContent"></asp:ContentPlaceHolder>
</form>

这篇关于每页绕过ASP.NET的一个RUNAT SERVER FORM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆