ajbzch1932
New Member
Hello, <BR><BR>I'm having problems passing the value of a variable to a user control. I got a suggestion yesterday, but still can't seem to get it to work, and advice is greatly appreciated.<BR><BR>I've no problem passing predefined strings <BR><Temp:header Runat="server" ID="header" strPath="../"/> <BR><BR>But if I try and pass the value of a variable I can't<BR><Temp:header Runat="server" ID="header" strPath="<%=strPath%>"/> <BR><BR>The suggestion I got was to<BR><BR>Sub Page_Load(s As Object, e As EventArgs) <BR> strPath = "../" <BR><BR> header.strPath = strPath <BR>End Sub <BR><BR>but this returns:<BR>Reference to a non-shared member requires an object reference.<BR><BR>thanks<BR>the best method I've found to passing values to a user control is to use the querystring. You could also possibly use codebehind pages, never tried it though, text files, & session variables.Thanks for the reply jeff, problem is that the variable is a constant defined on the aspx page that is then passed to the user controlTry something like this
if not using sessions variables)<BR>ASPX.page-<BR><BR>Sub Page_Init(Sender as Object, E as EventArgs)<BR>'declare variables(depending on use on aspx page <BR>'might want to move to a global position outside the sub<BR>Dim sid As String<BR> 'if sid does not exist create it<BR> sid = trim(request.querystring("sid"))<BR> IF NOT sid.Length > 0 THEN<BR> sid = system.guid.NEWGUID().ToString<BR> END IF<BR> 'set a hidden field to the value so that <BR> 'user controls can get to the value<BR> lblSID.Text = sid<BR>End Sub<BR><!---placeholder for global value---><BR><ASP:Label id=lblSID runat=server visible=false /><BR><BR>ASCX.page-<BR>'depending on how nested this point is from the label <BR>on the aspx page, you may have to add or remove parents.<BR>Dim sid As String = src.parent.parent.FindControl("lblSID").Text<BR><BR>T<TEMP:HEADER id="header" Runat="server" strPath='<%# strPath %'/><BR><BR>Then in the aspx page load event have<BR>Databind()
