|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using Server.Transfer with HyperLinkColumn in a datagridHello 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... 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 elton_w***@hotmail.com >-----Original Message----- the first page>Hello all, >I am trying to pass page properties between two pages and >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. The error isPage_Load method >during the loading of the properties of the previous >'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 pageShow quoteHide quote >is transfered? I am developing using C# as code behind to aspx. > >Thanks... > >-- >Message posted via http://www.dotnetmonster.com >. > 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. 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 Show quoteHide quote >-----Original Message----- Bold="True"></HeaderStyle> >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- Show quoteHide quote > <ItemStyle Font-Size="11px" Wrap="False" is where the error> 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 Show quoteHide quote >ocurrs > prop1 = p1.Property1; > prop2 = p1.Property2; >} > >I hope this is enough to work with. > >-- >Message posted via http://www.dotnetmonster.com >. > 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. 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----- trying to do here and>I want to refer you to a page that explains what I am >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 useShow quoteHide quote
5th Re-Post with NO RESPONSE FROM MS!
Can't get a reference to user control in datagrid Questions concerning detailsview or datagrid ASP.NET 2.0 How to capture CheckChanged event from Radiobutton in Datagrid? Problem with Top And Bottom Paging radiobutton and datagrid Make links different color in the datagrid search function on different page selected Handling events for Checkbox in Data Grid Change HeaderText of datagrid after binding |
|||||||||||||||||||||||