I have this very simple control below. And on the page that i use this control I’d just like to be able to say: ucMessagePanel.SetMessage(...), but it does not allow me to declare a static method. I tried doing it with Static properties and that works just fine, but shouldn’t I also be able to use static methods?
<center>
<asp:Panel ID="pnlMessage" runat="server" >
<asp:Label ID="lblMessage" runat="server" />
</asp:Panel>
</center>
public partial class ucMessagePanel : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public static void SetMessage(string message, string mssgCssClass)
{
lblMessage.Text = message;
pnlMessage.CssClass = mssgCssClass;
}
}
You don’t need static methods. When you declare the user control in the ASPX page, you can reference it directly by the ID.
In the ASPX:
And in the code behind:
In the user control, change the method to something like this: