c# thoughtworks qrcode Choosing a Method to Navigate Pages in Visual C#

Generator QR Code in Visual C# Choosing a Method to Navigate Pages

Choosing a Method to Navigate Pages
Draw QR Code ISO/IEC18004 In C#
Using Barcode creation for Visual Studio .NET Control to generate, create QR-Code image in VS .NET applications.
www.OnBarcode.com
Decode QR Code In Visual C#
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
There are many ways to navigate from one page to another in ASP.NET. It s helpful to first identify these ways and then examine each in detail. The following are the methods for page-to-page navigation in an ASP.NET site:
Encoding Barcode In C#.NET
Using Barcode maker for Visual Studio .NET Control to generate, create bar code image in .NET framework applications.
www.OnBarcode.com
Recognize Barcode In Visual C#.NET
Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Client-side navigation Client-side code or markup allows a user to request a new webpage. Your client code or markup requests a new webpage in response to a clientside event, such as the click of a hyperlink or the execution of JavaScript as part of a button click. Cross-page posting
Create QR Code In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications.
www.OnBarcode.com
Painting Quick Response Code In VS .NET
Using Barcode creator for VS .NET Control to generate, create QR-Code image in .NET applications.
www.OnBarcode.com
A control and form are configured to post back to a webpage that is different than the one that made the original request.
Draw Quick Response Code In VB.NET
Using Barcode generator for VS .NET Control to generate, create QR Code image in .NET applications.
www.OnBarcode.com
Printing UPCA In Visual C#
Using Barcode creation for .NET framework Control to generate, create UPC-A image in .NET framework applications.
www.OnBarcode.com
ChAPTER 5
Create Code128 In Visual C#
Using Barcode maker for .NET Control to generate, create Code 128 image in Visual Studio .NET applications.
www.OnBarcode.com
Barcode Maker In Visual C#
Using Barcode encoder for VS .NET Control to generate, create bar code image in .NET framework applications.
www.OnBarcode.com
Input Validation and Site Navigation
Create EAN13 In C#.NET
Using Barcode creation for VS .NET Control to generate, create EAN13 image in VS .NET applications.
www.OnBarcode.com
USPS POSTal Numeric Encoding Technique Barcode Generator In Visual C#
Using Barcode generation for VS .NET Control to generate, create USPS POSTNET Barcode image in VS .NET applications.
www.OnBarcode.com
Client-side browser redirect Server-side code sends a message to the browser, informing the browser to request a different webpage from the server. server-side transfer
Encoding PDF 417 In None
Using Barcode creator for Software Control to generate, create PDF417 image in Software applications.
www.OnBarcode.com
ECC200 Recognizer In Visual Basic .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Server-side code transfers control of a request to a different
Making Bar Code In Java
Using Barcode generator for Eclipse BIRT Control to generate, create bar code image in BIRT reports applications.
www.OnBarcode.com
Create Linear 1D Barcode In Visual Studio .NET
Using Barcode creator for VS .NET Control to generate, create 1D image in .NET applications.
www.OnBarcode.com
webpage.
Encode USS Code 128 In None
Using Barcode printer for Font Control to generate, create Code 128 Code Set A image in Font applications.
www.OnBarcode.com
Recognizing Bar Code In Visual C#
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Client-Side Navigation
Paint QR Code 2d Barcode In None
Using Barcode generation for Software Control to generate, create QR image in Software applications.
www.OnBarcode.com
EAN-13 Supplement 5 Maker In Objective-C
Using Barcode creator for iPad Control to generate, create European Article Number 13 image in iPad applications.
www.OnBarcode.com
One of the easiest ways to allow navigation to a different webpage is to provide a HyperLink control on the form and set the NavigateUrl property to the desired destination. The HyperLink control generates an HTML anchor tag, <a>. The NavigateUrl property is placed into the href attribute of the <a> element. The following example shows both the source of a HyperLink control and its rendered HTML.
HyperLink Control: Source <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/NavigateTest2.aspx">Goto NavigateTest2</asp:HyperLink> HyperLink Control: Rendered HTML <a id="HyperLink1" href="NavigateTest2.aspx">Goto NavigateTest2</a>
In this example, if this control is placed on a webpage called NavigateTest1.aspx, and the HyperLink control is clicked, the browser simply requests the NavigateTest2.aspx page. This means that no data is posted to NavigateTest2.aspx. If NavigateTest2.aspx requires data, you need to find a way to get the data to the page. One way to do this is to embed the data in the query string in the NavigateUrl property of the HyperLink control. Another means of forcing client-side navigation is through JavaScript. In this case, you write code to perform webpage navigation by changing the document object s location property to a new URL. The document object represents the webpage in client-side JavaScript; setting its location property causes the browser to request the webpage defined by the location property s value. The following example contains an HTML button element with a bit of client-side JavaScript to request a new page when the button is clicked.
<input id="Button1" type="button" value="Goto NavigateTest2" onclick="return Button1_onclick()" />
Notice that the onclick event is configured to call the client-side method, Button1_onclick. The JavaScript source for the Button1_onclick method is added into the <head> element of the page as follows.
<script language="javascript" type="text/javascript"> function Button1_onclick() { document.location="NavigateTest2.aspx"; } </script>
Lesson 2: Performing Site Navigation
ChAPTER 5
Once again, the NavigateTest2.aspx page is requested, and no data is posted back to the web server. Of course, you could send data into the function as part of a parameter and then append that data to the query string of the request.
Cross-Page Posting
Cross-page posting is frequently the best choice in a scenario in which data is collected on one webpage and processed on another webpage that displays the results. In such a scenario, a Button control typically has its PostBackUrl property set to the webpage to which the processing should post back. The page that receives the postback receives the posted data from the first page for processing. This page is referred to as the processing page. The processing page often needs to access data that was contained inside the initial page that collected the data and that delivered the postback. The previous page s data is available inside the Page.PreviousPage property. This property is set only if a cross-page post occurs. If the PreviousPage property is set to Nothing (null in C#), no cross-page posting occurred. You can access the controls found in the previous page by using the FindControl method of the PreviousPage property (which is a NamingContainer). In the following example, a webpage called DataCollection.aspx contains a TextBox control called TextBox1 and a Button control that has its PostBackUrl set to ~/ProcessingPage.aspx. When the data collection page invokes the processing page, it executes server-side code to pull the data from the data collection page, encode it by using HtmlEncode, and then put it inside a Label control. The code to do so is as follows.
Sample of Visual Basic Code Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load If Page.PreviousPage Is Nothing Then LabelData.Text = "No previous page in post" Else LabelData.Text = _ Server.HtmlEncode(CType(PreviousPage.FindControl("TextBox1"), TextBox).Text) End If End Sub Sample of C# Code protected void Page_Load(object sender, EventArgs e) { if(Page.PreviousPage == null) { LabelData.Text = "No previous page in post"; } else { LabelData.Text = Server.HtmlEncode(((TextBox)PreviousPage.FindControl("TextBox1")).Text); } }
Copyright © OnBarcode.com . All rights reserved.