Hi,
I just tried what you are describing above and it works. I made a user control that has a public string.
using System;
namespace WebApplication1
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public string myString = "myString";
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Included the control in an .aspx page.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register TagPrefix="test" TagName="MyControl" Src="~/WebUserControl1.ascx" %>
<asp:content id="HeaderContent" runat="server" contentplaceholderid="HeadContent" xmlns:asp="#unknown">
</asp:content>
<asp:content id="BodyContent" runat="server" contentplaceholderid="MainContent" xmlns:asp="#unknown">
<test:mycontrol id="MyControl" runat="server"></test:mycontrol>
<asp:label id="Label1" runat="server" text="Label"></asp:label>
</asp:content>
And set the label control above to show what is in the public string.
using System;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = MyControl.myString;
}
}
}
Works as expected.. or did I get your question wrong?
Cheers!