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. How can I get the HTML of a ASP control before rendering?

How can I get the HTML of a ASP control before rendering?

Scheduled Pinned Locked Moved ASP.NET
tutorialquestionhtmlcom
4 Posts 3 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.
  • V Offline
    V Offline
    Venkatesh Mookkan
    wrote on last edited by
    #1

    Hi all, I need know whether I could get the HTML of the control before rendering. For example, Lets take a ASP MenuItem. I inherits to my own MyMenuItem. I need to add some properties like OnClientClick for which I need the HTML of the MenuItem. Is that possible? If so how to do it (any sample code) Thanks in Advance

    [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

    M 1 Reply Last reply
    0
    • V Venkatesh Mookkan

      Hi all, I need know whether I could get the HTML of the control before rendering. For example, Lets take a ASP MenuItem. I inherits to my own MyMenuItem. I need to add some properties like OnClientClick for which I need the HTML of the MenuItem. Is that possible? If so how to do it (any sample code) Thanks in Advance

      [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

      M Offline
      M Offline
      Member_3259094
      wrote on last edited by
      #2

      try this namespace MyProject.ViewManeger { /// /// Summary description for ViewManager /// public class ViewManager { public static string RenderView(string path)//path of the user control { return RenderView(path, null); } public static string RenderView(string path, object data) { Page pageHolder = new Page(); UserControl viewControl = (UserControl)pageHolder.LoadControl(path); if (data != null) { Type viewControlType = viewControl.GetType(); FieldInfo field = viewControlType.GetField("Data"); if (field != null) { field.SetValue(viewControl, data); } else { throw new Exception("View file: " + path + " does not have a public Data property"); } } pageHolder.Controls.Add(viewControl); StringWriter output = new StringWriter(); HttpContext.Current.Server.Execute(pageHolder, output, false); return output.ToString(); } }

      Rajeev Kr. Sharma VRI Software Pvt.Ltd. New Delhi India HumOnline.com Stay Connected

      V 1 Reply Last reply
      0
      • M Member_3259094

        try this namespace MyProject.ViewManeger { /// /// Summary description for ViewManager /// public class ViewManager { public static string RenderView(string path)//path of the user control { return RenderView(path, null); } public static string RenderView(string path, object data) { Page pageHolder = new Page(); UserControl viewControl = (UserControl)pageHolder.LoadControl(path); if (data != null) { Type viewControlType = viewControl.GetType(); FieldInfo field = viewControlType.GetField("Data"); if (field != null) { field.SetValue(viewControl, data); } else { throw new Exception("View file: " + path + " does not have a public Data property"); } } pageHolder.Controls.Add(viewControl); StringWriter output = new StringWriter(); HttpContext.Current.Server.Execute(pageHolder, output, false); return output.ToString(); } }

        Rajeev Kr. Sharma VRI Software Pvt.Ltd. New Delhi India HumOnline.com Stay Connected

        V Offline
        V Offline
        Venkatesh Mookkan
        wrote on last edited by
        #3

        Thanks for replying Rajeev. But I am talking about Custom controls, but you are saying about User Controls. Thanks

        [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

        E 1 Reply Last reply
        0
        • V Venkatesh Mookkan

          Thanks for replying Rajeev. But I am talking about Custom controls, but you are saying about User Controls. Thanks

          [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

          E Offline
          E Offline
          eyeseetee
          wrote on last edited by
          #4

          Could you not apply the code to custom controls instead?

          We are not a Code Charity

          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