在我的网站上实现了母版页,但现在表单不起作用

发布于 2024-11-15 20:00:13 字数 14166 浏览 3 评论 0原文

我刚刚使用母版页实现了我的网站。所以它加载相同的页眉和页脚 对于每一页, 现在我的表格不再起作用了。 尝试将

标记移动到母版页内部和外部,但仍然没有任何结果。

母版页:

<%@ 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");不显示,并且在我拥有母版页之前它曾经显示过。

I just implemented my website with a Master Page. so it loads the same header and same footer
for every page,
and now my forms doesn't work anymore.
tried to move the <form> tag inside the master page and outside and still nothing.

Master Page:

<%@ 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");
    }
}

The problem is that the Respone.Write("cmdLogin"); doesn't show up, and it used to show up before i had the Master Page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浅忆 2024-11-22 20:00:14

即使您使用母版页,您仍然只能从中得到一个标记。因此,请这样看:

母版页:

<html>
<head>
</head>
<body>
<form method='POST' action='index.aspx'>

<placeholder>

</form>
</body>
</html>

WebForm:

<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 中写入响应

Even when you are using a master page, you still only get one markup coming out of it. So look at it this way:

Master Page:

<html>
<head>
</head>
<body>
<form method='POST' action='index.aspx'>

<placeholder>

</form>
</body>
</html>

WebForm:

<content>
<input type='text' value='hello' />
<input type='submit' value='Submit' />
</content>

output Markup

<html>
<head>
</head>
<body>
<form method='POST' action='index.aspx'>

<input type='text' value='hello' />
<input type='submit' value='Submit' />

</form>
</body>
</html>

The point is that if you use a form in both, you can expect to have nested forms appear on the final markup if you have forms in both. This is just an outline of what it can look like. If you post your pages we can give you more appropriate assistance.

Edit

Take advantage of the OOP available in C# - Create a Button object and append it to the page. You will always have a reference to it that way. Avoid writing to the response in asp.Net

や莫失莫忘 2024-11-22 20:00:14

@Danpe - 您是否查看过在单击 cmdLogin 按钮之前呈现的页面源代码?您是否在 page_load 中放置了一个断点来查看 Request.Form["cmdLogin"] 的值是什么?

除非您使用 Framework 4 和静态控件 ID 机制,否则 cmdLogin 按钮的 ID/名称实际上不会是“cmdLogin”,而是经过修改的名称,以确保 ID 不会与页面中的其他控件冲突。我相信,自 ASP.Net 诞生以来,这一直是标准行为。

由于 cmdLogin 是服务器端控件,因此在代码隐藏中添加按钮单击事件处理程序实际上会更好,而不是尝试手动解析表单参数。您似乎正在与 Web Forms 提供的功能作斗争。

@Danpe - have you taken a look at the page source that is rendered before you click the cmdLogin button? Have you placed a break point in the page_load to see what the value of Request.Form["cmdLogin"] is?

Unless you are using Framework 4 and static control ID mechanism, the ID/name of the cmdLogin button will not actually be "cmdLogin", but rather a modified name to ensure that ID does not conflict with other controls in the page. This has been standard behavior of ASP.Net since its inception, I believe.

Since cmdLogin is a server-side control, you would actually be better served by adding a button click event handler in the codebehind, rather than trying to manually parse the form parameters. You seem to be fighting with the features that Web Forms provides.

月依秋水 2024-11-22 20:00:14

将此:更改

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

Change this:

<input type="submit" name="cmdLogin" value="Login" id="cmdLogin" class="red-button" tabindex="3" runat="server" />

to this:

<asp:Button id="cmdLogin" Text="Login" CSSClass="red-button" tabindex="3" runat="server" />

and then in the .cs file you can access the button by:

cmdLogin.Text = "newText";

Edit

add this to the asp:Button tag

OnClick="ClickedFunction"

OR

add this to the .cs file:

protected override void onInit(EventArgs e)
{
    cmdLogin.Click += new EventHandler(cmdLogin_click);
}

void cmdLogin_click(object sender, EventArgs e)
{
    //Code for click here
}
今天小雨转甜 2024-11-22 20:00:14

将表单声明移至母版页,如下所示:

<body>
    <form id="form1" runat="server">

Move your form declaration to the master page, something like:

<body>
    <form id="form1" runat="server">
谁的年少不轻狂 2024-11-22 20:00:14

尝试从母版页中删除此块:

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

Try removing this block from the master page:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文