Results 1 to 10 of 10

Thread: [Resolved]Includes and Code Behind modules craziness

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    [Resolved]Includes and Code Behind modules craziness

    Hi there, I have a page which has 1 inlcude. The inlcude is a top navigation that has a label on it and it's called "loginheader.aspx". The label on this page is called lblMarquee and is runat the server so i can do things with it in my code behind module.

    The problem is you are only allowed 1 code behind module per page. Meaning that when these 2 pages are put together in the browser there can only be 1 code behind module and not 1 for each page.

    But the problem is I can not figure out how to access the control on the included page. The code behind module is with the main page login.aspx. This page has it's own controls that I check against a database etc..

    So my problem is, I have 2 pages that have controls on them that have to be accessed by the same code behind module.

    I have tried refrencing the other page like
    loginheader.lblMarquee.Text ="asdad"
    but i get the error saying i cant becasue it is Protected... So i set the Label as Public Withevents instead of Protected and i get a totaly different error.

    Sigh....

    Any help is appreciated!

    Thanks!
    Last edited by Arc; Jun 26th, 2003 at 10:16 AM.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Instead of using an include, make a control. It is basically a mini html page for you, you can have a code behind for it, and still keep it seperate from the page it is on.

    If you look at my site:
    http://www.variantx.com/Main/Index.aspx
    you will notice in the header, right under the graphic I have a label that tells you which page you are on. The whole header is done with a control. That control has its own code behind file that does the processing for the lable.

  3. #3

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Make what sort of control? And if i make a change to this control do i have to change every page or only change it once and it effects every page?

    I don't see any control that allows you to make navigations...
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    .ascx controls. I think the term is custom server controls....but don't quote me...lol.

    The best thing about them is you create one, then you can add it to every page, one page, or any number of pages. Then if you need to make a change, all pages will be changed just by editing the control code itself. It works just like an include.

    As far as not seeing any control for navigations, that is right, there isn't one. I was just trying to show you that my header on my web site is a control, I just drag it on to new pages and my header will be just the same on the new page as it is on the old pages.

  5. #5

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    I see, i thought you ment there was an existing control.

    I suppose I could create a "custom" control as a header navigation.. but surely to god there has to be an easier way to use includes and code behind modules together.

    I mean each page is considered a class so i even figured i create an instance of loginheader.aspx and get to the label that way but i cant becasue it says i am refrencing a null object...?

    In old VB with forms you would just say Form2.lblBlah ="ASDADS" how come you can't do that asp.net?

    Dim Lbl as New loginheader

    loginheader.lblBlah.Text = "ASDASD"

    Blah this sux. In PHP this would be so simple. But in php i wouldnt be using labels either.. i would just be putting the code where i wanted it.
    Last edited by Arc; Jun 25th, 2003 at 09:18 PM.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  6. #6

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Well i still think there has to be a better way to go about it, but i took your suggestion hellswraith and it works

    Thanks alot!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    You dont need includes. Period. .ascx controls do EXACTLY what you want and can be accesed from Code Behinds as if you were working with ANY other object.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by Cander
    You dont need includes. Period. .ascx controls do EXACTLY what you want and can be accesed from Code Behinds as if you were working with ANY other object.
    That was what I was trying to say, they have been made specifically for the reasons you are stating. They are awesome and VERY powerful once you get the hang of them.

    I use one for a header, one for a footer, and I use them anywhere that I think maybe I could reuse this functionality. They are sweet.

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes Cander and Hellswraith converted me to ascx controls also and I second what they have to say.

  10. #10

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Yah i've been experimenting with these things and they really are simple to make and very easy to use and you can make the code behind modules that mix in with otther ones. It really is the best way to go.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


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