|
-
Jul 8th, 2005, 05:22 PM
#1
Thread Starter
Hyperactive Member
access modifier trouble
I did fine when I was buidling win32 apps, but when I am doing web apps, I am having trouble using a public variable or sub on another page. It does not see it even if I reference the other class. The only thing I see under the other class is global?
-
Jul 9th, 2005, 10:02 AM
#2
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".
-
Jul 9th, 2005, 11:26 PM
#3
Thread Starter
Hyperactive Member
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?
-
Jul 11th, 2005, 03:59 AM
#4
Re: access modifier trouble
Explain your question in more detail.
-
Jul 11th, 2005, 11:30 AM
#5
Thread Starter
Hyperactive Member
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.
-
Jul 11th, 2005, 02:13 PM
#6
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");
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|