Using Server.Transfer with HyperLinkColumn in a datagrid

Discussion in 'ASP .Net Datagrid Control' started by Elton Wang, Mar 15, 2005.

  1. Elton Wang

    Elton Wang Guest

    Hi Jason,

    Without more detailed info, it's hard to say what's wrong
    in you application.

    Personally, I don't think it will cause trouble to pass
    any data to the second page without using Server.Transfer.

    Elton Wang


    >-----Original Message-----
    >Hello all,
    >I am trying to pass page properties between two pages and

    the first page
    >contains a datagrid loaded dynamically from a data access

    and the second
    >page needs one item from the query string and the

    provided properties from
    >the previous page. I am getting an error from the second

    Page_Load method
    >during the loading of the properties of the previous

    page. The error is
    >'Specified cast is not valid' which is consistant with an

    error that occurs
    >when you do not use Server.Transfer( ... ) to access the

    second page ( I
    >think this is the reason for the error ). My question is

    do you think this
    >is the source of my error and if so is there a way to

    control how the page
    >is transfered? I am developing using C# as code behind to

    aspx.
    >
    >Thanks...
    >
    >--
    >Message posted via http://www.dotnetmonster.com
    >.
    >
     
    Elton Wang, Mar 15, 2005
    #1
    1. Advertising

  2. Elton Wang

    Elton Wang Guest

    First of all, you should understand the web application is
    completely different from windows application. It's so
    called stateless that means once you move from one page to
    another page the first page is disappeared. You can't
    refer to it and of course, can't get any data from it.
    When you go back to the first page, it actually re-
    initializes a new instance.

    In order to transfer data between pages within an
    application, you can use ApplicationState, SeesionState,
    ViewState, or Cookie to save data in these objects, and
    then share the data in different pages. In your case, you
    can use SessionState to save data in page1. Then in page2
    retrieve the data from SessionState.

    To save data to SessionState:
    Session("keyName") = obj;

    To retrieve data from SessionState:
    ObjectType obj = (ObjectType)Session("keyName");

    HTH

    Elton Wang


    >-----Original Message-----
    >Here is an example of my code and error location.
    >The full code is much to large to post so here is an

    abstract.
    >
    >Page1.aspx.cs
    >
    >public string Property1
    >{
    > get
    > {
    > return prop1;
    > }
    >}
    >
    >public string Property2
    >{
    > get
    > {
    > return prop2;
    > }
    >}
    >
    >page1.aspx
    >
    >populate a datagrid via data access and
    ><Columns>
    > <asp:HyperLinkColumn DataNavigateUrlField="LocationID"
    > DataNavigateUrlFormatString="page2.aspx?ID=

    {0}"
    >DataTextField="LocationName" HeaderText="Store">
    > <HeaderStyle Font-Size="11px" Font-

    Bold="True"></HeaderStyle>
    > <ItemStyle Font-Size="11px" Wrap="False"
    > HorizontalAlign="Left"CssClass="blueLink"
    > VerticalAlign="Top"></ItemStyle>
    > </asp:HyperLinkColumn>
    >
    >bla bla....
    ></Columns>
    >
    >page2.aspx.cs
    >//define prop1 and prop2 as strings
    >
    >private void Page_Load
    >(object sender, System.EventArgs e)
    >{
    > //create instance of source web form
    > page1 p1;
    >
    > //get reference to current handler instance
    > p1 = ( page1 )Context.Handler; <-------Here

    is where the error
    >ocurrs
    > prop1 = p1.Property1;
    > prop2 = p1.Property2;
    >}
    >
    >I hope this is enough to work with.
    >
    >--
    >Message posted via http://www.dotnetmonster.com
    >.
    >
     
    Elton Wang, Mar 15, 2005
    #2
    1. Advertising

  3. Elton Wang

    Elton Wang Guest

    Of course, it's fine if you use query string to pass
    parameters to second page.

    In your case, you can use

    page2.aspx?prop1=p1Value&prop2=p2Value

    to access page2 from page1.

    In page2, use

    string p1 = Request.QueryString.Get("prop1");
    string p2 = Request.QueryString.Get("prop2");

    to retrieve those values.

    HTH

    Elton Wang


    >-----Original Message-----
    >I want to refer you to a page that explains what I am

    trying to do here and
    >it is located @

    http://www.dotnetbips.com/displayarticle.aspx?id=79
    >I work for a large company and we have rules in place

    governing what I can
    >and cannot use such as session state state management. We

    have to use a
    >component that requires the use of a database and for

    what I am doing that
    >is much more overhead then I want at this time, but if I

    have to I will use
    >it. I hope this explains my purpose.
    >
    >--
    >Message posted via http://www.dotnetmonster.com
    >.
    >
     
    Elton Wang, Mar 15, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vtreddy
    Replies:
    0
    Views:
    2,074
    vtreddy
    Nov 6, 2003
  2. =?Utf-8?B?RGF2ZQ==?=

    Can't apply CSS class to DataGrid's HyperlinkColumn?

    =?Utf-8?B?RGF2ZQ==?=, Feb 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,078
    Martin Dechev
    Feb 27, 2004
  3. Rob Meade

    Datagrid - HyperLinkColumn

    Rob Meade, Aug 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    589
    Rob Meade
    Aug 9, 2004
  4. debiken
    Replies:
    0
    Views:
    270
    debiken
    Nov 17, 2003
  5. Jim
    Replies:
    1
    Views:
    949
    Aaron Bertrand - MVP
    Jan 28, 2004
Loading...

Share This Page