Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Method of Page navigation in ASP.NET

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 711
    Comment on it

    Page navigation means moving from one page to another in you website.  In ASP.NET, there are different methods for navigation. These navigations are : 

    1. Client-side navigation
    2. Cross-page posting
    3. Client-side browser redirect
    4. Server-Side Transfer

    Client-side navigation :  It allows user to  navigate from one page to another using client side code or HTML. In this method,  links and information about the web page that it could navigate to are contained by the markup page of the rendered page. When the user wants  to navigate using  markup that includes hyper-link or button -click, the browser takes him to the requested page. 

    There are two methods used in client-side navigation :

    1. Using HyperLinkControl: 

    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Welcome.aspx">  </asp:HyperLink>

    2. Through JavaScript :

    Take an HTML button control on web page. Following is the HTML code for the input button. 

    <input id="Button1" type="button" value=" next page" onclick="return Button1_onclick()" />

       Button1_onclick will be called, when the Button1 is clicked. The source code is shown below:

    <script language="javascript" type="text/javascript">
    function Button1_onclick() 
    {
        document.location="NavigateTest.aspx";
    }
    
    </script>

    Cross-page posting : This method is used to configure the controls in  web page to navigate users' posted data  to some other page instead of the original page. This method is used to gather data from the user and then pass it on to some other page for processing.

    For e.g :  Lets suppose we have two pages, the first page is Default.aspx and Second page is Page.aspx. The First Page has a Button and TextBox control and its ID is Button1 and TextBox1 respectively. A Button control has its PostBackUrl property. Set this property to “~/Page.aspx”. When the user clicks on Button, the data will send to SecondPage for processing. The code for SecondPage is as follows:

    protected void Page_Load(object sender, EventArgs e)
    {
        if(Page.PreviousPage == null)
        {
            Label1.Text = "No previous page in post"; 
        } 
        else
        {
            Label1.Text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
        }
    }

    The second page contains a Label control and its ID is Label1.

    The page that receives the PostBack receives the posted data from the first page which  is considered as the processing page.The processing page often needs to access data that was contained inside the initial page that collected the data and delivered the PostBack. The previous page’s data is available inside the Page.PreviousPage property. This property is only set if a cross-page post occurs.

    Client-side browser redirect : This navigation method was initiated from server side. Some code running on the server will tell the user's browser to navigate to another page.In this, the Page.Response object contains the Redirect method.

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect ("demo.aspx"); 
    }

    Server Side Transfer : In this method, the server will initiate the navigation like Client side browser redirect. In this technique Server.Transfer method is used.  The Transfer method transfers the entire context of a Web page over to another page. The page that receives the transfer generates the response back to the user’s browser.

    protected void Button1_Click(object sender, EventArgs e) 
    { 
        Server.Transfer("Default.aspx", false); 
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: