[Solved] JavaScript not working in Master Page in ASP.Net

nauna
 
on Jul 10, 2021 06:56 AM
484 Views

hello,

I have this solution on master page its not working but on single page it works

        <asp:ScriptManager runat="server" />
        <asp:UpdatePanel ID="updpaging" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Panel ID="Panel1" runat="server" Height="200px" ScrollBars="Vertical">
                    <asp:Button ID="btnshowmore" runat="server" Text="Show More" mousehover="stopTheTimer()" />
                    <asp:Timer ID="timer" runat="server" Interval="1000" OnTick="Timer1_Tick">
                    </asp:Timer>
                    <asp:Label ID="lblTime" runat="server" />
                    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
                    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
                </asp:Panel>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnshowmore" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
        <script type="text/javascript">
            $("body").on("mouseover", "[id*=Panel1]", function () {
                stopTheTimer();
            });
            $("body").on("mouseout", "[id*=Panel1]", function () {
                startTheTimer();
            });
            $(window).scroll(_.debounce(function () {
                stopTheTimer();
            }, 150, { 'leading': true, 'trailing': false }));
 
            $(window).scroll(_.debounce(function () {
                startTheTimer();
            }, 150));
            function stopTheTimer() {
                $find('<%= timer.ClientID %>')._stopTimer();
            }
 
            function startTheTimer() {
                $find('<%= timer.ClientID %>')._startTimer();
            }
        </script>

 

protected void Timer1_Tick(object sender, EventArgs e)
{
    lblTime.Text = DateTime.Now.ToString();
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 13, 2021 01:05 AM

Hinauna,

Code is working in master page.

Refer the code.

HTML

<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="updpaging" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server" Height="200px" ScrollBars="Vertical" Style="border: 1px solid red;">
            <asp:Button ID="btnshowmore" runat="server" Text="Show More" mousehover="stopTheTimer()" />
            <asp:Timer ID="timer" runat="server" Interval="1000" OnTick="Timer1_Tick">
            </asp:Timer>
            <br />
            <asp:Label ID="lblTime" runat="server" />
            <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
            <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        </asp:Panel>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnshowmore" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script type="text/javascript">
    $("body").on("mouseover", "[id*=Panel1]", function () {
        stopTheTimer();
    });
    $("body").on("mouseout", "[id*=Panel1]", function () {
        startTheTimer();
    });
    $(window).scroll(_.debounce(function () {
        stopTheTimer();
    }, 150, { 'leading': true, 'trailing': false }));

    $(window).scroll(_.debounce(function () {
        startTheTimer();
    }, 150));
    function stopTheTimer() {
        $find('<%= timer.ClientID %>')._stopTimer();
    }

    function startTheTimer() {
        $find('<%= timer.ClientID %>')._startTimer();
    }
</script>

Code

protected void Timer1_Tick(object sender, EventArgs e)
{
    lblTime.Text = DateTime.Now.ToString();
}

Screenshot