我刚用Master Page实现了我的网站。所以它加载相同的标题和相同的页脚
对于每一页,
现在我的表格不再起作用了。
试图在主页面和外面移动<form>
标签,但仍然没有。
母版页:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="WebSite.master.cs" Inherits="WebSite.WebSite" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><asp:ContentPlaceHolder ID="titleContent" runat="server" /></title>
<link href="Resources/css/styles.css" rel="stylesheet" type="text/css" />
<link href="Resources/css/jqModal.css" rel="stylesheet" type="text/css" />
<link href="Resources/css/boxy.css" rel="stylesheet" type="text/css" />
<link href="Resources/css/form.css" rel="stylesheet" type="text/css" />
<script src="Resources/js/swfobject.js" type="text/javascript" > </script>
<script src="Resources/js/jquery-1.3.2.min.js" type="text/javascript" > </script>
<script src="Resources/js/jqModal.js" type="text/javascript"> </script>
<script src="Resources/js/soundmanager.js" type="text/javascript" > </script>
<script src="Resources/js/JScriptFunctions.js" type="text/javascript" > </script>
<script src="Resources/js/jquery.boxy.js" type="text/javascript" ></script>
<script src="Resources/js/styled.js" type="text/javascript" ></script>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form name="aspnetForm" method="post" id="aspnetForm" runat="server">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<div id="wrapper">
<div id="animation">
<div id="ctl00_singleBannerHomePage_pnlFlashContent">
</div>
<script language="javascript" type="text/javascript">
generateBanner(980, 220, 'ctl00_singleBannerHomePage_pnlFlashContent', 'bannersingleBannerHomePage', 'http://www.WebSite.com//Resources//flash/topmenu.swf', '');
</script>
</div>
<div class="banner" style="text-align: center;">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="960" height="120"
id="logo_250x105" align="middle">
<param name="movie" value="Resources/flash/banner_960x120.swf">
<param name="quality" value="high">
<param name="play" value="true">
<param name="loop" value="true">
<param name="wmode" value="transparent">
<param name="scale" value="showall">
<param name="menu" value="true">
<param name="devicefont" value="false">
<param name="salign" value="">
<param name="allowScriptAccess" value="sameDomain">
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="Resources/flash/banner_960x120.swf"
width="960" height="120">
<param name="movie" value="/resources/flash/banner_960x120.swf">
<param name="quality" value="high">
<param name="play" value="true">
<param name="loop" value="true">
<param name="wmode" value="transparent">
<param name="scale" value="showall">
<param name="menu" value="true">
<param name="devicefont" value="false">
<param name="salign" value="">
<param name="allowScriptAccess" value="sameDomain">
<!--<![endif]-->
<a href="https://www.adobe.com/go/getflash">
<img src="Resources/get_flash_player.gif" alt="Get Adobe Flash player">
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
<asp:ContentPlaceHolder ID="Main" runat="server">
</asp:ContentPlaceHolder>
<div id="footer">
<div id="menu_footer">
<ul>
<li><a id="ctl01_lnkMenuOption" href="http://www.WebSite.com/">
Home</a></li>
<li class="separator">|</li>
<li><a id="ctl03_lnkMenuOption" href="http://www.WebSite.com/">
Login</a></li>
<li class="separator">|</li>
<li><a id="ctl05_lnkMenuOption" href="http://www.WebSite.com/register">
Free Register</a></li>
<li class="separator">|</li>
<li><a id="ctl07_lnkMenuOption" href="http://www.WebSite.com/how">
How Does it work</a></li>
<li class="separator">|</li>
<li><a id="ctl15_lnkMenuOption" href="http://www.WebSite.com/winners">
Winners List</a></li>
<li class="separator">|</li>
<li><a id="ctl17_lnkMenuOption" href="http://www.WebSite.com/myAccount">
Members</a></li>
<li class="separator">|</li>
<li><a id="ctl19_lnkMenuOption" href="http://www.WebSite.com/">
Site Map</a></li>
<li class="separator">|</li>
<li><a id="ctl21_lnkMenuOption" href="http://www.WebSite.com/contact">
Contact</a></li>
<li class="separator">|</li>
<li><a id="ctl23_lnkMenuOption" href="http://www.WebSite.com/terms">
Terms & Policy</a></li>
<li class="separator">|</li>
<li><a id="ctl25_lnkMenuOption" href="http://www.WebSite.com/about">
About</a></li>
</ul>
<ul>
<li><a href="http://www.WebSite.com/" target="_blank">Beta</a></li>
<li class="separator">|</li>
<li><a href="http://www.WebSite.com/" target="_blank">Beta</a></li>
<li class="separator">|</li>
<li><a href="http://www.WebSite.com/" target="_blank">Beta</a></li>
<li class="separator">|</li>
<li><a href="http://www.WebSite.com/" target="_blank">Beta</a></li>
<li class="separator">|</li>
<li><a href="http://www.WebSite.com/" target="_blank">Beta</a></li>
<li class="separator">|</li>
<li><a href="http://www.WebSite.com/" target="_blank">Beta</a></li>
<li class="separator">|</li>
<li>
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" addthis:url="http://www.facebook.com/pages/WebSite/187442987973985" ></a>
<a class="addthis_button_tweet" addthis:url="http://www.WebSite.com/" ></a>
<a class="addthis_counter addthis_pill_style" addthis:url="http://www.WebSite.com/" ></a>
</div>
<script type="text/javascript"> var addthis_config = { "data_track_clickback": true };</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=danpe"></script>
<!-- AddThis Button END -->
</li>
<li class="separator">|</li>
<li><a href="http://www.WebSite.com/" target="_blank">WebSite © 2011</a></li>
</ul>
</div>
</div>
<object type="application/x-shockwave-flash" id="flashAlert" name="flashAlert" data="Resources/flash/AlertPlayer.swf"
width="1" height="1">
</object>
</form>
<script type="text/javascript">
$(document).ready(function () {
$('#adscaptcha_facebook_like_holder').remove();
$('#adscaptcha_buttons_holder').remove();
$('#adscaptcha_r4').remove();
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23547527-1']);
_gaq.push(['_setDomainName', '.WebSite.com']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
的Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="Default" MasterPageFile="~/WebSite.Master" Title="" %>
<asp:Content ID="ContentTitle" ContentPlaceHolderID="titleContent" Runat="Server">
WebSite!
</asp:Content>
<asp:Content ID="ContentHead" ContentPlaceHolderID="head" Runat="Server">
<meta name="AUTHOR" content="WebSite.com">
<meta name="CLASSIFACTION" content="auction, auctions">
<meta name="RATING" content="GENERAL">
<meta name="DISTRIBUTION" content="GLOBAL">
<meta name="REVISIT" content="1 DAYS">
<meta name="ROBOTS" content="INDEX,FOLLOW">
<meta property="og:title" content="WebSite! - SecondLife Auctions" />
<meta property="og:site_name" content="WebSite" />
<meta property="og:image" content="hhttp://www.WebSite.com/Resources/images/logo.png" />
<meta property="og:url" content="http://www.WebSite.com/" />
<meta property="fb:admins" content="1277633739" />
<link rel="image_src" href="http://www.WebSite.com/Resources/images/logo.png" />
<link rel="SHORTCUT ICON" href="http://www.WebSite.com/WebSite.ico" />
<script type="text/javascript">
function alertMe(message) {
var options = $.extend({ title: "Information" }, options || {});
var dialog = new Boxy("<div><p>" + message + "<a href='#' onclick='Boxy.get(this).hide(); return false'>Close me!</a></p></div>", options);
allDialogs.push(dialog);
return false;
}
</script>
<script type="text/javascript">
var message = "Impossible Action";
function clickIE() { if (document.all) { return false; } }
function clickNS(e) {
if
(document.layers || (document.getElementById && !document.all)) {
if (e.which == 2 || e.which == 3) { return false; }
}
}
if (document.layers)
{ document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS; }
else { document.onmouseup = clickNS; document.oncontextmenu = clickIE; }
document.oncontextmenu = new Function("return false")
</script>
<style type="text/css" media="screen">
#ctl00_singleBannerHomePage_pnlFlashContent
{
visibility: hidden;
}
</style>
</asp:Content>
<asp:Content ID="ContentMain" ContentPlaceHolderID="Main" Runat="Server" >
<div id="content">
<div class="sign-in-home">
<div class="login-form-home">
<% Response.Write(LoginPanel()); %>
<input type="submit" name="cmdLogin" value="Login" id="cmdLogin" class="red-button" tabindex="3" runat="server" />
</div>
</div>
<div class="login-text-home"></div>
</div>
<div class="sort-by-home">
<% Response.Write(SortPanel()); %>
</div>
<% Response.Write(Auctions()); %>
<script type="text/javascript">
$(document).ready(function () {
startAuctionsServiceHomePage();
});
</script>
</asp:content>
default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Page_Load");
if (Request.Form["cmdLogin"] != null && Request.Form["cmdLogin"] != "")
{
Response.Write("cmdLogin");
}
}
问题是 Respone.Write(“cmdLogin”);没有出现,它曾经出现在我拥有母版页之前。
答案 0 :(得分:3)
即使您使用母版页,您仍然只能获得一个标记。所以这样看:
母版页:
<html>
<head>
</head>
<body>
<form method='POST' action='index.aspx'>
<placeholder>
</form>
</body>
</html>
web窗体:
<content>
<input type='text' value='hello' />
<input type='submit' value='Submit' />
</content>
输出标记
<html>
<head>
</head>
<body>
<form method='POST' action='index.aspx'>
<input type='text' value='hello' />
<input type='submit' value='Submit' />
</form>
</body>
</html>
关键在于,如果您在两者中都使用表单,那么如果您在两者中都有表单,则可以期望在最终标记上显示嵌套表单。这只是它的外观轮廓。如果您发布网页,我们可以为您提供更合适的帮助。
修改的
利用C#中提供的OOP - 创建一个Button对象并将其附加到页面。你总会以这种方式引用它。避免写入asp.Net中的响应
答案 1 :(得分:2)
@Danpe - 您是否看过在单击cmdLogin按钮之前呈现的页面源?您是否在page_load中放置了一个断点,以查看Request.Form [“cmdLogin”]的值是什么?
除非您使用的是Framework 4和静态控件ID机制,否则cmdLogin按钮的ID /名称实际上不是“cmdLogin”,而是修改后的名称,以确保ID不与页面中的其他控件冲突。这是ASP.Net自成立以来的标准行为,我相信。
由于cmdLogin是服务器端控件,因此在代码隐藏中添加按钮单击事件处理程序实际上可以更好地服务,而不是尝试手动解析表单参数。您似乎正在与Web窗格提供的功能进行斗争。
答案 2 :(得分:1)
将表单声明移动到母版页,例如:
<body>
<form id="form1" runat="server">
答案 3 :(得分:1)
改变这个:
<input type="submit" name="cmdLogin" value="Login" id="cmdLogin" class="red-button" tabindex="3" runat="server" />
到此:
<asp:Button id="cmdLogin" Text="Login" CSSClass="red-button" tabindex="3" runat="server" />
然后在.cs文件中,您可以通过以下方式访问该按钮:
cmdLogin.Text = "newText";
修改的
将此添加到asp:Button标记
OnClick="ClickedFunction"
或强>
将其添加到.cs文件中:
protected override void onInit(EventArgs e)
{
cmdLogin.Click += new EventHandler(cmdLogin_click);
}
void cmdLogin_click(object sender, EventArgs e)
{
//Code for click here
}
答案 4 :(得分:0)
尝试从母版页中删除此块:
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>