Sharing objects between .ascx and .aspx

smerch

New Member
(VB.NET)<BR><BR>When working with a page that has a user control, how do <BR>you share objects(and their members) between the .aspx <BR>and the child .ascx? <BR><BR>Say for instance the .aspx declares your connection <BR>object and you want ot use that object in the .ascx?<BR><BR>Or you have a property in the .ascx and you wish to <BR>access it in the .aspx?<BR><BR>The problem I have come across is that the page's On_Load <BR>fires, the program flow passes to the .ascx, and by the <BR>time you get to the page's Page_UnLoad, all the variables <BR>for the user control have disappeared.<BR><BR>I know that variables defined in the .aspx are linked to <BR>those with the same name in the .ascx, but for objects <BR>that aren't form objects there is no persistence it seems.<BR><BR>Thanks,<BR><BR>Josh<BR>for >>><BR>"Say for instance the .aspx declares your connection <BR>object and you want ot use that object in the .ascx?<BR><BR>Or you have a property in the .ascx and you wish to <BR>access it in the .aspx?"<BR><BR>Just declare the objects as public properties in the Control. To set properties of the control in the ASPX:<BR><MyUC:GenParams id="myGenParamUC" runat="server" strVendor="fid" strWorkSpace="crs" lngRuleID="20080"/> <!--Sets 4 properties of the control--><BR><BR>To Access properties of the ASCX from the ASPX:<BR>response.write(myGenparamUC.strVendor) 'will write the strVendor property of the controlWhat if strVendor="" wasn't a string but instead an object with properties, methods, etc?just tried it and it does not work!!! There's got to be a way.. will post if I find out....
 
Back
Top