Results 1 to 6 of 6

Thread: access modifier trouble

  1. #1

    Thread Starter
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    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?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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".

  3. #3

    Thread Starter
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    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?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: access modifier trouble

    Explain your question in more detail.

  5. #5

    Thread Starter
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    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.

  6. #6
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    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
  •  



Click Here to Expand Forum to Full Width