Load Page. VB vs Javascript. Need opinion. Thank You.

S

Shapper

Hello,

I am working on an ASP.NET/VB web site.
I have several links including menu links.

Considerer a want to load a page named page.aspx.

I can do it using javascript. Or using this code:
Sub loadPage(sender As Object, e As System.EventArgs, pageURL as
String)
Response.Redirect(pageURL)
End Sub

What are the advantages or disadvantages of each method?

Which one should I use?

Thanks,
Miguel
 
L

Lucas Tam

I can do it using javascript. Or using this code:
Sub loadPage(sender As Object, e As System.EventArgs, pageURL as
String)
Response.Redirect(pageURL)
End Sub

What are the advantages or disadvantages of each method?

Javascript can be disabled.

Server side will require a round trip. But a server side transfer will
allow you to log what happened (or do additional processing).

Personally I'll choose a sever side transfer.
 
K

Kevin Spencer

Think of these software entities as tools. In that context, think of one as
a Framing hammer, and one as a Finishing hammer. Now, in that context, how
would you answer the following question:
What are the advantages or disadvantages of each method?

Answer: There are no "advantages" or "disadvantages" to either. There are
properties and characteristics. Neither good nor bad, unless used in some
context. For example, a Framing hammer is perfect for framing. A Finishing
hammer is perfect for finishing. But a Framing hammer will make a mess if
you use it for finishing, and a finishing hammer will take forever to build
a frame.

Again, using the hammer analogy, how would you answer the following:
Which one should I use?

Answer: Use the tool that has the characteristics and properties that are
appropriate for the given situation. If you're building the frame of a
house, use a framing hammer. If youre putting in moulding, use a finishing
hammer.

So much for the philosophy. Now let me answer your specific questions, posed
in a more appropriate fashion:

What are the characteristics and properties of each method?

Actually, you have more options than the ones you mentioned, such as:

Client-side:
JavaScript
Hyperlink
Server-side:
Response.Redirect
Server.Transfer

And a few others that are much less common, and used for special purposes.

On the client side, a hyperlink is the simplest method to load a different
document into the browser, and if you're strictly talking about links in a
menu, I would go with that. Remember that the links can also include
QueryStrings to pass data to the new page. You can use JavaScript if you
need additional client-side processing, need to open the page in a new
window (which you can also do with a hyperlink, but with less control over
the window), or for somewhat more complex situations.

On the server side, Response.Redirect is often useful, as it causes the
browser to make a second request for the new document. The Redirect
directive is added to the HTTP headers in the Response, causing the browser
to load the new document. With Response.Redirect, you can use a QueryString
to send data to the new page. Note that with Response.Redirect, you are
sending a GET request for the new page. Server.Transfer can be useful in
situations where you need to transfer server-side resources and memory from
one page instance to the other. Note that Server.Transfer does NOT tell the
browser to request a different page, but transfers server-side processing to
the new page, and the browser "thinks" it is still looking at the same page
(URL).

When should I use one or the other?

Again, a hyperlink is the simplest and fastest way of transferring to a new
page. with the addition of a QueryString to the hyperlink, you can also send
data to the new page. JavaScript is also fast, but a little more complex,
and is useful in situations where you need to do additional CLIENT-side
processing, or have control over a new window, such as resizing it, or
setting up the status bar, and other browser elements in the new window.

Response.Redirect can be the simplest way of transferring to a new page, if,
for example, you have some server-side condition that changes and requires a
redirect to a new page. Rather than returning the same page to the client,
and requiring additional client-side processing to transfer, you can do the
Redirect which causes the browser to request the new page, without looking
as if it had received the first page in the first place. However, it should
be noted that Response.Redirect actually causes the browser to make TWO
Requests, one for the first page, and one for the redirected page, and
involves some network latency. Server.Transfer has the advantage of not
requiring a second Request from the browser, but remember that it returns a
new page with the same URL as the original page. Server.Transfer can be
useful when you want to do a partial Response from one page, and finish it
from another.

If you keep these characteristics of each method in mind, it should become
apparent at what time(s) to use which method(s).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
S

Shapper

Thanks Kevin for your description of the most common options I have.
I will be useful in the future.

Cheers,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top