Server.Transfer Help

  • Thread starter Thread starter Jeremy
  • Start date Start date
J

Jeremy

I'm having some problems with using Server.Transfer and I
am hoping somebody can help me.

Page 1 has a datagrid, Page 2 has a form.

If a user goes to page 1 and selects something out of the
datagrid I want to transfer the value of that records item
number in the grid over to page 2. I use the passed
number to retrieve data from a database and populate the
form.

So far, what I've explained I have working. My problem is
that when I go directly to page 2 I get an error about an
invalid cast type and I want to see a blank form that I
can use to insert a new record into the db (as opposed to
updating an existing record when the value gets transfered
to the form).

I am hoping that somebody can explain to me how to do this.

Thanks,
Jeremy
 
I'm not really sure how you have this setup, but my initial impression is
that you may want to consider constructing it a little differently. Namely,
use a client-side redirect instead of a server.transfer.

I dunno how you would logistically do this with a datagrid, but I'm assuming
it's possible - on Page 1, when a user clicks a record, instead of
server.transfering to Page 2, perform a client-side redirect to Page 2 and
include the record value in the query string, e.g. redirect to
"page2.aspx?Record=<someVariablevalue>"

Then I would create Page 2 so that it looks for the query string Record
value in it's Page_Load event, and if it finds it, it does it's thing and
populates the form based on the Record value. If it doesn't find the Record
value (or if it's an illegal value), then default to the behavior of
creating a new record.

This would create a structure where Page 2 knows how to behave independantly
of Page 1, and Page 2 could be called from any page that is able to pass it
an appropriate value.

You may be able to do a response.redirect in the datagrid's click event, or
you may have to use a registerOnSubmit on Page 1 to intercept the postback
event... not sure which better ( or works ), if either.

Hope I'm not too off base here trying to help...
 
Thanks for the reply. That's exactly how I had it before,
however, I kept having problems. Not really sure why, but
when I would click on a link that goes back to the grid
and then select the same item the form would be empty. I
tried making sure the page wasn't cached but that didn't
help.

So what I wanted to do was once the page recognized that a
user wanted to select something from the grid it would set
a public property variable to be the value of the item in
the grid and transfer it's processing over to the form
page. And I would have the form page try to recognize if
the data was being passed and do all the stuff you said.
However, I'm not exactly sure how to do this.

Jeremy
 
Back
Top