19 September 2011

handles the process of moving between pages asp.net


This time I will discuss one of the basic techniques of web programming is about handling the process of moving between web pages at ASP.NET. To simplify the process of transfer between the terms of this page, in this article, I use the term navigation is more concise. In ASP.NET, a web page commonly referred to as a web form. Means that we will learn through this article is how to make the navigation or connecting many web forms that we make.
Navigation between the web form is needed when we have a number of web forms more than one. In most cases, at least we always need a pair of web forms to deal with a process. A pair of web form or page can we refer to as pages and pages RESPONSE FORM. FORM page or we could call the page form, serves as the recipient of the data or input from the user / users.Page RESPONSE function displays a confirmation page or pages that should be addressed after the process is complete. Examples include navigation navigation cases after the data storage and general navigation to another page or what we refer to as a link.
Materials Preparation Exercises Before I explain some navigation techniques in ASP.NET, we should prepare training materials in advance. Training material is shaped web application that we will create in Visual Studio. For that, create an ASP.NET web application that let's call PoetryWeb2. You can follow the steps to make ASP.NET web applications via Visual Studio in the previous article. For purposes of this exercise, leave the default page as the original without remained altered. We will make some modifications later. Then create a web form again with the following steps:
Right click on project name and select Add. You will see a list of new sub-menu is displayed. Choose New Item on the sub-menu that appears. You'll see the Add New Item dialog. In the Templates section, make sure you have selected a Web Form. If not sure, then click the Web Form option in the list of Templates. Then look at the Name. If you perform the previous steps correctly you'll see the words WebForm1.aspx. That is the name of the new web form that we will create. We'll change the name into Response.aspx. Click the Add button then a new web form, Response.aspx, will appear under PoetryWeb2 project and automatically opened by Visual Studio. Add the following text into the form tag in Response.aspx: This is a page .. RESPONSE This paper will we see when we managed to navigate to the page Response.aspx. Three Ways to Navigation in ASP.NET When we use ASP.NET web page, we have the 3 (three) ways to navigate. FIRST, we can use standard HTML tags to link the anchor or we usually know as <A>. SECOND, we can use the ASP.NET Button control. THIRD, we can use other ASP.NET control is LinkButton. We will learn how to navigate one by one by directly applying it to the application exercises that we have previously made the PoetryWeb2.
Navigation with HTML Anchor This navigation technique is the easiest way because it does not require ASP.NET controls and did not require programming in C #.So, what we do is insert the HTML anchor tag into a web page (web form). As you probably know before, the use of the HTML anchor tag is quite easy because we live complete the information on the href attribute and text links that we want. For more details, we will conduct practice directly.
Open the Default.aspx page. Then do the modifications in the FORM tag as follows:
<form id="form1" runat="server">
  
<div>
    
<a href="Response.aspx"> Go to Response with Anchor </ a>
  
</ Div> </ Form> Note that we only need to enter a destination page in the href attribute is Response.aspx and text that will be clicked the Go To Response with Anchor. In this way we do not need to recompile. If we click the link text then we will move from the page Default.aspx to the page Response.aspx and see the words â € œIni is RESPONSE.â page €?? which we write before.
Navigation with Button When we use the ASP.NET Button control then we need to do programming in C # to provide navigation commands. Navigation commands will be executed when we click the navigation button that we created. To do so, the ASPX file, we need to add an ASP.NET Button control and then complete the attribute or property ID and OnClick. In ASPX.CS file, we will add code or code to navigate to the page Response.aspx command. For more details, do the modification on Default.aspx and Default.aspx.cs file by adding the following code fragments:
Default.aspx:
<form id="form1" runat="server">
  
<div>
    
ID="btnGoTo" <asp:Button runat="server" Text="Go to Response" OnClick="btnGoTo_Click" />
  
</ Div> </ Form> Default.aspx.cs:
protected void btnGoTo_Click (object sender, EventArgs e) {
  
Response.Redirect ("Response.aspx"); Through this way navigation button, we begin to learn more about programming in C # that is on the use of a command or function or method Response.Redirect (). This serves the function or method to navigate to a given page. In this case we give the destination page as a parameter. To test the code we have made, we need to compile it first. When we have to compile it, then we can press the button with the words â € œGo To Responseâ €?? and we will move from the page Default.aspx to the page Response.aspx.
Navigation with Link Button LinkButton Control allows us to navigate more flexible. LinkButton Control provides 2 (two) ways of navigation which can be selected according to the type of navigation that we need. The first way is the easiest way, namely by entering the name of the destination page on PostBackUrl attribute. The second method, similar to the use of Button for navigation, namely by making the navigation commands through C # code. Both methods are equally generate the navigation from the home page to page navigation purposes.We'll just try two ways to create 2 (two) control LinkButton. Add the following code snippet code in the appropriate file:
Default.aspx:
<form id="form1" runat="server">
  
<div>
    
<asp:LinkButton ID="lbtGoTo1" runat="server" PostBackUrl="Response.aspx"> Go to Response 1 </ asp: LinkButton>
    
<br />
    
<asp:LinkButton ID="lbtGoTo2" runat="server" OnClick="lbtGoTo2_Click"> Go to Response 2 </ asp: LinkButton>
  
</ Div> </ Form> Default.aspx.cs:
protected void lbtGoTo2_Click (object sender, EventArgs e) {
  
Response.Redirect ("Response.aspx"); Notice in the Default.aspx code, we use a new tag that is <BR/>.The tag serves to place the LinkButton lbtGoTo2 in the new line.Thus 2 (two) control LinkButton we will neatly arranged on different lines. Moreover, the code above will function like a navigation-navigation we've ever tried before.
Thus the explanation of the navigation techniques that can be done in ASP.NET and C #. Please use the attached source code or please ask if you have trouble. May be useful.
TOOLS: Used: Visual Studio 2008 Professional Edition Alternative: Visual Studio 2005 Professional Edition, Visual Studio 2010 Professional Edition
SOURCE CODE: Please download the source code PoetryWeb2 here.

Tidak ada komentar:

Posting Komentar