Using Aspnet Components

If you were passing this information via the query string,the code would look a little different compared to posting through a form.

See ASPResponse_ai.aspx for the full example on the CD.

Example:

<H3>Welcome to mylifetimegoals.com</H3>

What suggestions do you have for improving our site?

<FORM RUNAT="Server" METHOD="GET">

<ASP:DROPDOWNLIST ID="dropdownlistSuggestions" RUNAT="Server"> <ASP:LISTITEM>Fewer Goals</ASP:LISTITEM> <ASP:LISTITEM>More Goals</ASP:LISTITEM> <ASP:LISTITEM>Same Number of Goals</ASP:LISTITEM> </ASP:DROPDOWNLIST>

<ASP:BUTTON ID="buttonExample" RUNAT="Server" TEXT="Submit"/><P/> <% if (IsPostBack) {

Response.Write(Request.QueryString["dropdownlistSuggestions"]);

_Q Add a set of script delimiters after the button.

— Save the file and request it from the Web server.

^ Click 0 and select a suggestion.

_Q Add a set of script delimiters after the button.

LQ Add an if statement to make sure that the code will only run when posting to the page.

|Add the Request.Form method to retrieve the value that was selected in the dropdown list box.

LE Add the Response.Write method to write the value selected in the drop-down list box.

— Save the file and request it from the Web server.

■ The Web page for submitting suggestions appears.

^ Click 0 and select a suggestion.

m Click the Submit button.

■ The suggestion you chose appears.

DIRECT USING RESPONSE.REDIRECT

You can use the HTTPResponse class to redirect users to other pages besides the page they originally requested. One situation where you can use a redirect is when you delete an existing page off of your Web site. For example, if you come up with a new naming convention for pages on your site, you can keep the old pages on the site with a redirect to the replacement page. You can also use a redirect to handle an error on a Web page. When the error occurs, you can redirect them to a standard error page. Another common use of redirects is on a page that processes the user's request and redirects the user based on what is in the user's Request object.

To redirect a user's request, you can use Response. Redirect. When performing redirects, you need to make sure that no HTTP response packets have been sent to the user requesting the page. If any HTTP packets have been sent and you perform a redirect, you will generate a server error. To avoid getting this server error, you can buffer the response by adding the page directive at the top of the file and setting Buffer=True.

REDIRECT USING RESPONSE.REDIRECT

REDIRECT USING RESPONSE.REDIRECT

Q Open the Suggestions.htm template from the Code Templates directory.

■ The contents of the page contains a suggestions form.

□ Open a new document in your text editor.

□ Add a pair of script delimiters.

-Q Request the data from the drop-down list box and read it into a string variable.

Q Open the Suggestions.htm template from the Code Templates directory.

Add the ACTION value to the form.

■ The contents of the page contains a suggestions form.

□ Open a new document in your text editor.

Add the page directive, set the language to C#, and buffer the page.

□ Add a pair of script delimiters.

-Q Request the data from the drop-down list box and read it into a string variable.

Was this article helpful?

0 0

Post a comment