Redirect to specific part of page on Anchot tag Click in ASP.Net

Last Reply 7 months ago By pandeyism

Posted 7 months ago

it's in master page when i href to gallery it's work but when i want return Default.aspx to part About it doesn't work

        <div id="mySidenav" class="sidenav">
            <div class="sidenav-content">
                <ul class="nav-center list-unstyled" id="nav">
                  <a href="javascript:void(0)" id="closebtn" onClick="closeNav()">&times;</a>
                  <li><a href="Default.aspx#mypage" onClick="closeNav()">Home</a></li>
                  <li><a href="Default.aspx#about-us" onClick="closeNav()">About</a></li>
                  <li><a href="Default.aspx#services" onClick="closeNav()">Services</a></li>
                  <li><a href="team.aspx" onClick="closeNav()">Team</a></li>
                  <li><a href="gallery.aspx" onClick="closeNav()">Work</a></li>
                  <li><a href="Default.aspx#contact" onClick="closeNav()">Contact</a></li>
                </ul>
            </div>
        </div>

 

 

You are viewing reply posted by: pandeyism 7 months ago.
Posted 7 months ago

Hi sani.ss501,

Refer below sample.

HTML

MasterPage.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div id="mySidenav" class="sidenav">
        <div class="sidenav-content">
            <ul class="nav-center list-unstyled" id="nav">
                <li><a href="Default.aspx#section1" class="button">Aspnippets</a></li>
                <li><a href="Default.aspx#section2" class="button">Forums</a></li>
                <li><a href="Default3.aspx#section1" class="button">ContactUs</a></li>
            </ul>
        </div>
    </div>
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
    </asp:ContentPlaceHolder>
    </form>
</body>
</html>

Default.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="section1">
        <h1>
            Welcome to ASPSnippets.com</h1>
        Here mudassar Ahamad Khan write articles.
    </div>
    <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 /><br /><br /><br /><br /><br /><br /><br />
    <div id="section2">
        <h1>
            ASPForums.net</h1>
        Here we make code as per professional developer requirements.
    </div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</asp:Content>

Default2.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

Default3.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="section1">
        <h1>
            ContactUs</h1>
        abcd@gmail.com 
        544156654165
    </div>
    </form>
</body>
</html>

Screenshot