Creating a "Back" button in VB.Net/ASP.Net

C

Coleen

Yes, I know why would I want to create a back button when there is one on
the browser? Because that's what the users want! they want a "Previous"
button that they can click from any web page in our application that will do
the exact same thing as the Back button in the browser. Can anyone give me
any suggestions on how to do this using VB .Net? I have Googled for "Create
Back Button" and found stuff in JavaScript and HTML but nothing in VB .Net.
Can this be done as simply as doing a response.redirect? Any help would be
appreciated.

Coleen
 
H

Herfried K. Wagner [MVP]

Coleen said:
Yes, I know why would I want to create a back button when there is one on
the browser? Because that's what the users want! they want a "Previous"
button that they can click from any web page in our application that will
do
the exact same thing as the Back button in the browser. Can anyone give
me
any suggestions on how to do this using VB .Net? I have Googled for
"Create
Back Button" and found stuff in JavaScript and HTML but nothing in VB
.Net.
Can this be done as simply as doing a response.redirect? Any help would
be
appreciated.

As the action takes place on the client (as does pressing the browser's
"Back" button) you may want to use client-side JavaScript. Solutions can be
found on the Web.
 
C

Coleen

Yes, I know I can use JavaScript, thanks. I was trying to find out if there
is a way to do this using VB.Net? I have been reading all the help files
and searching on-line but can't find anything to accomplish this in VB .Net.
Is this not supported by .Net? Why is it that things that should be very
simple are so convoluted in .Net?
 
B

Bob Lehmann

Is this not supported by .Net?

Why would it be? .Net runs on the server, and you are trying to perform a
client action.
..Net?

What makes you think it's simple? Is because you think simply?

Or is it because you are trying so hard to *make* it not simple?

Why do you want to go back to the server to perform an action that is
handled more simply, and natively on the client?

What is convoluted about it?

Of course, if you insist on going back to the server, I guess you could
store the previous page in a session variable, post back to the server, read
the variable, and redirect to that page.

But, that would be not simple, and also very convoluted. Oh, yeah - and
stupid.

Bob Lehmann
 
C

Coleen

Thanks for your insults - I mean input!

Bob Lehmann said:
Why would it be? .Net runs on the server, and you are trying to perform a
client action.
.Net?

What makes you think it's simple? Is because you think simply?

Or is it because you are trying so hard to *make* it not simple?

Why do you want to go back to the server to perform an action that is
handled more simply, and natively on the client?

What is convoluted about it?

Of course, if you insist on going back to the server, I guess you could
store the previous page in a session variable, post back to the server, read
the variable, and redirect to that page.

But, that would be not simple, and also very convoluted. Oh, yeah - and
stupid.

Bob Lehmann
 
C

Coleen

Sorry I couldn't Resist :)

The plain "simple" truth is that I don't know JavaScript - and honestly do
NOT know that much about what calls the server and what calls the client so
I did not realize that Javascript does not call the server while .Net
does...so my remarks were in ignorance of .Net's capabilities not meant to
belittle .Net - only that I thought this should be a simple thing to do.

The problem I am having is that since I do not Know JavaScript, the code
that I have found on-line to do this simple (yes the CODE IS simple in
JavaScript and even in HTML!) but I am using a User Control that has
multiple buttons and I put the code for the Back button in the User Control
VB code-behind:

btn_prev.Attributes.Add("onclick", "javascript:history.go(-1);")
btn_prev.Attributes.Add("onclick", "javascript:history.back();")

Neither one of these works, and since I don't know JavaScript I do NOT know
how to get this to work!

If you have any suggestions I would appreciate them.

Coleen
 
A

aaron.kempf

i think that this would be complex in vb.net; i mean-- you would need
to encode an undo functionality to everything you.

perhaps starting a transaction and not commiting it would be the way to
go?

are you building data entry apps??

-Aaron
 
C

Coleen

Yes. The app is an on-line entry for users and we have created a "Footer"
user control that has all the buttons for Back, Submit, Next , Add, Clear or
Update the current page. Some buttons will have slightly different
functions from page to page, but buttons such as the Back, Next, and Submit
will always do the same thing. So I am trying to set up the code to do the
Back and next buttons in the User Control. The code I showed before for the
JavaScript doesn't work, so since I'm not a JavaScript programmer I don't
know how to troubleshoot it. If you have any suggestions on how to embed a
JavaScript function in a VB/ASCX User Control, I would greatly appreciate
any help.

Thanks :)

Coleen
 
C

Coleen

Okay - I got some help from someone who knows JavaScript here and we solved
this by putting the code:
btn_prev.Attributes.Add("onclick", "javascript: history.go(-1); return
false;")
in the Page load of the user control instead of in the Click event of the
control. Two things here - I was not using the return false option or
spacing the JavaScript code correctly, and the code has to be in the page
load not in the Click event. Any way, this is the solution for any one else
who comes across this problem.

Coleen
 

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