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