Avaricesoft’s Weblog

Just another WordPress.com weblog

Archive for June 10th, 2009

Sending the User to a New Page

Posted by avaricesoft on June 10, 2009

In the currency converter example, everything took place in a single page. In a more typical website, the user will need to surf from one page to another to perform different tasks or complete a single operation.There are several ways to transfer a user from one page to another. One of the simplest is to use an ordinary <a> anchor element, which turns a portion of text into a hyperlink. In this example, the word here is a link to another page: Click <a href=”newpage.aspx”>here</a> to go to newpage.aspx. Another option is to send the user to a new page using code. This approach is useful if you want to use your code to perform some other work before you redirect the user. It’s also handy if you need to use code to decide where to send the user. For example, if you create a sequence of pages for placing an order, you might send existing customers straight to the checkout while new visitors are redirected to a registration page. To perform redirection in code, you first need a control that causes the page to be posted back. In other words, you need an event handler that reacts to the ServerClick event of a control such as HtmlInputButton or HtmlAnchor. When the page is posted back and your event handler runs, you can use the HttpResponse.Redirect() method to send the user to the new page. Remember, you can get access to the current HttpResponse object through the Page.Response property. Here’s an example that sends the user to a different page in the
same website directory:

Response.Redirect(“newpage.aspx”);

When you use the Redirect() method, ASP.NET immediately stops processing the page
and sends a redirect message back to the browser. Any code that occurs after the Redirect() call won’t be executed. When the browser receives the redirect message, it sends a request for the new page. You can use the Redirect() method to send the user to any type of page. You can even send the user to another website using an absolute URL (a URL that starts with http://), as shown here:

Response.Redirect(“http://www.prosetech.com”);

ASP.NET gives you one other option for sending the user to a new page. You can use the HttpServerUtility.Transfer() method instead of Response.Redirect(). An HttpServerUtility object is provided through the Page.Server property, so your redirection code would look like this:

Server.Transfer(“newpage.aspx”);

The advantage of using the Transfer() method is the fact that it doesn’t involve the
browser. Instead of sending a redirect message back to the browser, ASP.NET simply starts processing the new page as though the user had originally requested that page. This behavior saves a bit of time, but it also introduces some significant limitations. You can’t use Transfer() to send the user to another website or to a non-ASP.NET page (such as an HTML page). The Transfer() method only allows you to jump from one ASP.NET page to another, in the same web application. Furthermore, when you use Transfer() the user won’t have any idea that another page has taken over, because the browser will still show the original URL. This can cause a problem if you want to support browser bookmarks. On the whole, it’s much more common to use
HttpResponse.Redirect() than HttpServerUtility.Transfer().

Regards,

Muhammad Kalim (+92-333-2352452)

Manager Business Development AVARICESOFT.com

Posted in ASP.net, C#.net | Tagged: , , , , , , , , | 5 Comments »

Session in asp.net

Posted by avaricesoft on June 10, 2009

What is Session:

This collection holds information for a single user, so it can be used in
different pages. For example, you can use the Session collection to store the
items in the current user’s shopping basket on an e-commerce website

First you should include the Session Collection by using Clause

using System.Web.SessionState;

How to Save the Data from Session State / How to Create the Session State in asp.net 2008:

  • suppose their is a class of user’s –>save the session object of username for userclass.

userclass uc = new userclass();

Session["username"] = uc.getusername();

  • getusername() return the username of string of the above code

How to Reterieve the Data Session from State / How to Get the Date from Session State in asp.net 2008:

  • Reterieve the data in other page using Session State of username here it is:

userclass uc1 = userclass();

uc1.setusername(Session["username"].ToString());

  • setusername is the public function of userclass which takes string parameter

Remove Unsused object of the Session State:

  • you should remove the Session State manually by coding its a best practices of the programmer and client hand side and server modules.

Session.["username"] = null;

  • not remove the Session State is define because where u have to null the Session State not remove its depend upon case to case.

Session.Remove["username"]

  • if you null the Session State then its not remove so best practice is to remove the Session State not null

Thanks All.

Regards,

Muhammad Kalim (+92-333-2352452)

Manager Business Development AVARICESOFT.com

if you have any query then write the comments.. i will help u out

Posted in ASP.net | Tagged: , , , , , , , , , , | 1 Comment »