Fluminda
Fluminda

Reputation: 85

microsoft jscript runtime error:test is undefined

I have 2 master pages 1 inside admin adn 1 outside admin

jquery function outside admin master page is firing on specific event and same functions when I copied from that file to adminmaster , i m getting eror

microsoft jscript runtime error:'functionname'is undefined

The difference here is content page of admin master having jquery function as well , and only those functions are available in viewsource page or firefox->firebug->script

The function which are inside adminmasre are not available at all.

here is my code for admin.master

<asp:ContentPlaceHolder ID="scriptadmin" runat="server"> 
    <script type="text/javascript">
        $(document).bind("mobileinit", function () {
            $.mobile.ajaxEnabled = false;
        });

        $("#Logout").click(function (e) {
            e.stopImmediatePropagation();
            e.preventDefault();
        });

        function test() {
            alert("Test");
        }

        function Dologout() {
            //     Sys.Services.AuthenticationService.logout(null, OnLogoutSuceeded, OnLoginFailed, null);
            // return false;
        }

        //         function OnLogoutSuceeded(result, userContext, methodName) {
        //             alert('You have been successfully logged out of the application...');
        //          //   window.location.href("Login.aspx");
        //         } 

</script>

</asp:ContentPlaceHolder>
</body>
</html>

and here is div where I called this function Back Logout

Content page is :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"      Inherits="XYZ.Admin.Default" MasterPageFile="~/Admin/admin.Master"  %>
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
        <h3 class="MainHeader">Upload Excel file to convert into database </h3>
        <asp:Label ID="lblmsg" runat="server" Text="" CssClass="message" ></asp:Label>
        <div class="file-upload-btn">
            <asp:FileUpload ID="FileUpload1" runat="server"  />
        </div>
        <div id ="ButtonWrapper" > 
            <asp:Button ID="btnUpload" runat="server" Text="Upload" data-role="none" onclick="btnUpload_Click"    />
        </div>
</asp:Content>

<asp:Content ID="script1" ContentPlaceHolderID="scriptadmin" runat="server">
    <script type="text/javascript">
         $(function () {
             $("#btnUpload").removeClass('ui-btn-hidden ui-btn-inner ui-submit ui-btn ui-shadow ui-btn-corner-all ui-btn-up-b');
             $("#FileUpload1").removeClass('ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-c file-upload-btn');
         });
    </script>
</asp:Content>

Any help would be appreciated!!

Upvotes: 0

Views: 2267

Answers (1)

mattmanser
mattmanser

Reputation: 5806

You've replaced the code inside the place holder scriptadmin, that's why those functions have disappeared.

The way ContentPlaceHolder work inside Master pages is that any code inside the Master file is only run if they inheriting file doesn't have that ContentPlaceHolder. It's default content, so you're replacing it.

What you need to do is change the Admin.Master and change it so the ContentPlaceHolder doesn't contain the default code, it's always added instead.

<script type="text/javascript">
    $(document).bind("mobileinit", function () {
        $.mobile.ajaxEnabled = false;
    });

    $("#Logout").click(function (e) {
        e.stopImmediatePropagation();
        e.preventDefault();
    });

    function test() {
        alert("Test");
    }

    function Dologout() {
        //     Sys.Services.AuthenticationService.logout(null, OnLogoutSuceeded, OnLoginFailed, null);
        // return false;
    }

    //         function OnLogoutSuceeded(result, userContext, methodName) {
    //             alert('You have been successfully logged out of the application...');
    //          //   window.location.href("Login.aspx");
    //         } 

</script>
<asp:ContentPlaceHolder ID="scriptadmin" runat="server" />

Upvotes: 1

Related Questions