How best to "navigate" (newbie)

  • Thread starter Thread starter Bill Cohagan
  • Start date Start date
B

Bill Cohagan

I'm a Windows Forms developer, but am trying to get a grip on how things are
done in a web UI (using ASP.Net). So, in a Windows Forms app, I might have a
dialog that displays a listbox populated from the Categories table in
Northwind. Next to that I'd have a button for adding a new category. So,
what's the typical way of doing this via a Web Forms UI?

I've got the listbox on the web form and can populate it. I've got the
associated button for adding a new category, but in the associated event
handler what do I do? What (I think) I want to do is open another page that
has the UI for specifying a new Category. I want to open this page
(replacing the original?), then when the user provides the necessary data
and clicks the Save button I want to save the new record to the database,
then go back to the original page, refreshing the listbox content to reflect
the newly added Category.

So far it's not clear to me the best way to open that second page and, given
that I do get there, how do I know to which page to "return" after the new
category is created? I'd like to be able to use this "new category" page
from several different pages so I can't hard wire the URL to return to? Do I
need to save the "return URL" as session state or is there some built in way
to reference the URL to the "previous" page?

This seems to be a basic pattern (and I see lots of possible ways to try),
but thought I'd ask for a little guidance from those who've no doubt done
this a million times.

Thanks in advance,
Bill
 
The Microsoft UIP Application Block comes with some very good built in
navigation architecture, BUT... since you're new to the web stuff, it might
be a bit more than you care to chew on right now.

The easy way out is to simply have the listbox, and the fields for the new
form all on the same page. Then, on the button's click event, you would
call whatever classes and methods are required to add the category to the
database. The code for the listbox generation will be run on each
request(unless you have it inside an If Not Page.IsPostback block).

Alternatively, you could call a Response.Redirect("AddCategory.aspx") where
AddCategory.aspx is the name of a separate page that contains the form for
collecting category info. On that page, you'd have a button as well, that
upon being clicked, would run the database update code. From there, you
could return to the category info form again, for adding a new category, or
you could just do another Response.Redirect, back to the main category list.

There are MANY other ways you could do this, but those are two of the
easiest for starters.

I was minding my own business when Bill Cohagan blurted out:
 
Chris-
Thanks for the response. It was the Response.Redirect approach that I was
thinking about, but the question is how do I know to which form (page) to
"return". As I said in my original post, I'd like to be able to use the
AddCategory.aspx page from several different calling pages. I could set the
"return address" as a session variable I suppose, but wondered if IIS/ASP
automatically provide a way to determine from within AddCategory the URL of
the previous page.

BTW, thanks for the pointer to the MS UIP Application Block. I had heard
of this, but forgotten about it.

Regards,
Bill
 
In the AddCategory page, when you're ready to return to the calling page,
you could do:

Response.Redirect(Request.ServerVariables("HTTP_REFERER"))

which is the same as the old CGI variable that simply tells you which page
the user came from. Using that method, it never really matters which page
you called AddCategory from.

Hope this helps. :-)


I was minding my own business when Bill Cohagan blurted out:
 
Chris-
It turns out that in my app the AddCategory page gets a postback prior to
needing to return to the "calling" page; thus using the HPPT_REFERER"
variable as you suggested just returns me back to AddCategory; however by
caching the initial value as a session state value on the initial page load
I'm able to return to the proper page. Thanks again for the help.

Bill
 
Well that makes sense. My mistake. Glad you figured out a way to make it
work though. :-)

I was minding my own business when Bill Cohagan blurted out:
 
Back
Top