Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Convert web page to user control...

Convert web page to user control...

Scheduled Pinned Locked Moved ASP.NET
javascriptdatabasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    code frog 0
    wrote on last edited by
    #1

    So I want to (as previously recommended) convert parts of my web page into a user control. I've added a .ascx file to the project but now I'm curious. I cannot just copy and paste into that... What do I do with the head, body and other elements? I've got a lot of javascript in the page as well can I make a user control out of it?

    Would I be better off to just stuff the parts of the .aspx code into a database pull them when I need them? Can this be done?

    Thanks in advance. Sorry I'm still new to all of this...

    Some assembly required. Code-frog System Architects, Inc.

    T 1 Reply Last reply
    0
    • C code frog 0

      So I want to (as previously recommended) convert parts of my web page into a user control. I've added a .ascx file to the project but now I'm curious. I cannot just copy and paste into that... What do I do with the head, body and other elements? I've got a lot of javascript in the page as well can I make a user control out of it?

      Would I be better off to just stuff the parts of the .aspx code into a database pull them when I need them? Can this be done?

      Thanks in advance. Sorry I'm still new to all of this...

      Some assembly required. Code-frog System Architects, Inc.

      T Offline
      T Offline
      turbochimp
      wrote on last edited by
      #2

      You can actually just cut and paste the html and web control declarations to the user control's design interface. The javascript too, if it's inline; if not (if you are importing a .js file or something) you can leave the reference on the page that will act as parent to the user control. User controls do not need a HEAD or BODY element (nor should you add a new server-side FORM element to them) because they are provided by the web form (aspx file) on which the user control is sited. User controls (ascx files) are rendered as if they were part of the parent web form (aspx file). The difference (and advantage) between user controls and web forms is that user controls can be used in numerous places without having to either rewrite or cut/paste/customize large chunks of markup and controls. User controls also support code-behind or code-inline. For most purposes, you can think of them as web forms that cannot be rendered by themselves, but must be declared or hosted in the source of a web form. Once your user control is complete and working, you can literally drag and drop it on one or more web forms, and it should work the same in all cases, provided you've designed it without dependencies on its hosting environment. Good luck.

      The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups