开发者

Implemented a Master Page to my site, and now forms doesn't work

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.


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


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


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
}


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

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜