Re: access modifier trouble
I don't know what you're trying to do with the pages, but you should create a separate class for the things you want "global".
Re: access modifier trouble
ok, that fixes a few things. I created a public class, placed in the app code folder, and can now reference that. How do I reference a specific form from that class now?
Re: access modifier trouble
Explain your question in more detail.
Re: access modifier trouble
Code:
Public Shared Sub NavTo(ByVal strLocation As String)
Dim frameLoad As New HtmlGenericControl
frameLoad = Me.FindControl("FrameLoad")
frameLoad.Attributes("src") = strLocation
End Sub
I need this sub to be public, but I cant use me for the findcontrol, so I need to reference that specific webform. If I put the sub in that webform it is fine, but then I cannot access it from any other forms.
Re: access modifier trouble
You have two options, as I see it:
1) Create a base class that extends System.Web.UI.Page that contains the function, and in your forms, extend your class:
Code:
public class MyBasePage: System.Web.UI.Page
{
protected void NavTo(string location)
{
HtmlGenericControl frameLoad = this.FindControl("FrameLoad");
if (frameLoad != null)
frameLoad.Attributes["src"] = location;
}
}
public class FooPage: MyBasePage
{
private void Button_Click(object sender, EventArgs e)
{
// This page instance will now have a method named "NavTo"; can call at will.
NavTo("/page.htm");
}
}
2) Provide the page instance to the static (shared) method:
Code:
public class CodeLib
{
public static void NavTo(System.Web.UI.Page target, string location)
{
HtmlGenericControl frameLoad = target.FindControl("FrameLoad");
if (frameLoad != null)
frameLoad.Attributes["src"] = location;
}
}
public class FooPage: MyBasePage
{
private void Button_Click(object sender, EventArgs e)
{
// Call the static function...
CodeLib.NavTo(this, "/page.htm");
}
}