Advice regarding best use of HTML / Web Controls in UserControl

Discussion in 'ASP .Net Web Controls' started by Brett, Jun 16, 2004.

  1. Brett

    Brett Guest

    Preface: I am a complete neophyte to ASP.NET development. Unfortunately
    the same holds true with respect to ASP development. I do consider myself
    advanced as far as OOP development with the .NET Framework goes.

    My question: I want to create a UserControl that will become part of a page
    template to keep my site consistent. This particular control is to be a
    sidebar menu that displays links to the various sections on my site. So far
    it looks like the best route is to design the usercontrol with a multi-row
    table that houses links to the other sections in each row. My question, I
    guess, is:

    Should I
    a.) use a System.Web.UI.WebControls.Table and programmatically add the
    'link' controls to the rows, or
    b.) should I create a plain HTML (not server) table on the UserControl and
    add the hyperlinks (via the designer) to each row.

    If b.) then should the links be ASP.NET server controls or should I do HTML
    controls there as well.

    The plot thickens a bit because I want client script to execute when the
    user mouses over the links (to highlight them). I understand if I use
    server side controls then I have to emit the JavaScript code when the page
    loads. This seems like a headache (not to mention a processing burden at
    each page load for something that will never change.) However I am having a
    lot of trouble trying to add HTML controls and coding the javascript into
    the HTML portion of the .ascx. I get an "<id> is undefined" error when the
    javascript event executes, which really amazes me since the IDE recognizes
    it when I am adding the javascript to the HTML code.

    Apparently I can't even figure out the proper way to phrase the question
    since I'm not finding a lot of help when I search the net. I hoping you
    guys will do a better job knowing what I mean (rather than what I say) than
    the search engines do.

    Thanks in advance,
    Brett
     
    Brett, Jun 16, 2004
    #1
    1. Advertising

  2. Brett

    S.Grevi Guest

    Brett, I had the same problems about adding Javascript in a .aspx page.

    Why a basically HTML based page wouldn't recognize accordingly a normal
    Javascript ? Because is not HTML, was my answer : it has placeholders for
    controls to be rendered AS HTML but IS NOT HTML, maybe XHTML ?

    Anyway, the phylosophy has to be putted away : the only way I found to have
    controls the events of which have to respond to Javascript code is using
    <control>.Attributes.Add(<event>,<clientJavascriptFunction>) in the
    code-behind.

    I'll try to answer to your first question :

    IMVHO

    a) is a good solution if you change often the links and/or the link list is
    taken from a db, an XML or other data sources. Server roundtrip is needed.
    b) is a good solution for statics and rarely modified links.

    So my answer is : it depends.

    I shed more light on your problem, or I didn't get the point ?

    Tell me.

    Stefano Grevi
     
    S.Grevi, Jun 17, 2004
    #2
    1. Advertising

  3. Brett

    Brett Guest

    Stefano, you got my point exactly. I just needed to hear how other
    *experienced* ASP.NET developers handled this type of scenario to see if I
    was on the right track. Thank you very much for your help.

    Brett

    "S.Grevi" <> wrote in message
    news:...
    > Brett, I had the same problems about adding Javascript in a .aspx page.
    >
    > Why a basically HTML based page wouldn't recognize accordingly a normal
    > Javascript ? Because is not HTML, was my answer : it has placeholders for
    > controls to be rendered AS HTML but IS NOT HTML, maybe XHTML ?
    >
    > Anyway, the phylosophy has to be putted away : the only way I found to

    have
    > controls the events of which have to respond to Javascript code is using
    > <control>.Attributes.Add(<event>,<clientJavascriptFunction>) in the
    > code-behind.
    >
    > I'll try to answer to your first question :
    >
    > IMVHO
    >
    > a) is a good solution if you change often the links and/or the link list

    is
    > taken from a db, an XML or other data sources. Server roundtrip is needed.
    > b) is a good solution for statics and rarely modified links.
    >
    > So my answer is : it depends.
    >
    > I shed more light on your problem, or I didn't get the point ?
    >
    > Tell me.
    >
    > Stefano Grevi
    >
    >
     
    Brett, Jun 17, 2004
    #3
  4. Deciding between A nad B choice is not so much about changes (as S.Grevi
    suggested), because your UserControl is rendered each time (and recreates
    all controls) you access it, but its more about functionality.

    If you just need to link to some aspx pages then I strongly suggest U use
    normal HTML and render it. Don't use server controls, because they are
    slower and use more resources.

    But if you have to I don't know change the state of your application (like
    area of work when someone clicks another link), then you have to use at
    least LinkButton controls.

    So the answer (as I see it) is:
    - for totally static part of the control (like tables, cells, rows, divs,
    etc.) use plain and simple HTML.
    - for all other controls that you need to have their state and handle their
    server events, use server controls (either WebControls or HTMLControls -
    depends on the requirements)...

    That's the best way.

    --
    RobertK
    { Clever? No just smart. }


    "Brett" <> wrote
    in message news:O3$...
    > Preface: I am a complete neophyte to ASP.NET development. Unfortunately
    > the same holds true with respect to ASP development. I do consider myself
    > advanced as far as OOP development with the .NET Framework goes.
    >
    > My question: I want to create a UserControl that will become part of a

    page
    > template to keep my site consistent. This particular control is to be a
    > sidebar menu that displays links to the various sections on my site. So

    far
    > it looks like the best route is to design the usercontrol with a multi-row
    > table that houses links to the other sections in each row. My question, I
    > guess, is:
    >
    > Should I
    > a.) use a System.Web.UI.WebControls.Table and programmatically add the
    > 'link' controls to the rows, or
    > b.) should I create a plain HTML (not server) table on the UserControl and
    > add the hyperlinks (via the designer) to each row.
    >
    > If b.) then should the links be ASP.NET server controls or should I do

    HTML
    > controls there as well.
    >
    > The plot thickens a bit because I want client script to execute when the
    > user mouses over the links (to highlight them). I understand if I use
    > server side controls then I have to emit the JavaScript code when the page
    > loads. This seems like a headache (not to mention a processing burden at
    > each page load for something that will never change.) However I am having

    a
    > lot of trouble trying to add HTML controls and coding the javascript into
    > the HTML portion of the .ascx. I get an "<id> is undefined" error when

    the
    > javascript event executes, which really amazes me since the IDE recognizes
    > it when I am adding the javascript to the HTML code.
    >
    > Apparently I can't even figure out the proper way to phrase the question
    > since I'm not finding a lot of help when I search the net. I hoping you
    > guys will do a better job knowing what I mean (rather than what I say)

    than
    > the search engines do.
    >
    > Thanks in advance,
    > Brett
    >
    >
     
    Robert Koritnik, Jun 18, 2004
    #4
  5. Brett

    S.Grevi Guest

    You are welcome, Brett.
    If 'experienced' is a person with only 9 months of development on .NET
    technology...

    I thought about the side effects of a User Control wrapping an HTML part :
    in this case you'll have always the server roundtrip because you put the
    placeholder of this control in the .aspx page and then it will be rendered
    as a <TABLE> in the HTML for the client, but the server has to do some work
    on this.

    If you have to control some server events, as stated by Robert, the HTML +
    server control solution in this case is needed, giving to you the
    'reusability' of the user control in your project.

    If you don't plan to reuse the links table and it's the only control you
    need...go HTML.
    It could be called and call aspx pages easily and it's faster.

    Have a nice day, Brett.

    Stefano

    "Brett" <> wrote
    in message news:...
    > Stefano, you got my point exactly. I just needed to hear how other
    > *experienced* ASP.NET developers handled this type of scenario to see if I
    > was on the right track. Thank you very much for your help.
    >
    > Brett
     
    S.Grevi, Jun 18, 2004
    #5
  6. Brett

    S.Grevi Guest

    I agree Robert.

    I'd add at the list you did only the possibility to 'reuse' the control, so
    a 'composition' of simple HTML controls IMHO could be grouped in a User
    Control for this. But in this case the server has to do some work, not so
    much but some.

    Stefano Grevi
     
    S.Grevi, Jun 18, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    698
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    423
    Rajesh Tiwari
    Aug 12, 2003
  3. Replies:
    0
    Views:
    482
  4. Kan Grewal

    Web Usercontrol in a Web Usercontrol not displaying...

    Kan Grewal, Jul 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    118
    Kan Grewal
    Jul 7, 2004
  5. Reik
    Replies:
    1
    Views:
    243
    Brock Allen
    Apr 12, 2005
Loading...

Share This Page