c# - Is there a way I can make a div runat server? So i can turn it into a control? -


Is there any way that I can create a div runat server? So can I turn it into a control? In asp.net?

EDIT:

How can I tell my code below to create the div id = test runarat server?

  while (reader.Read ()) {System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl ("div"); Div.Attributes ["class"] = "test"; //div.Style["float "] =" left "; Div.ID = "test"; Image IMG = new image (); Img.ImageUrl = String.Format ("{0}", reader.getstring (1)); // this line to SQL syntax // img Need to represent in iJurl = "~ / UserData / 2 / UploadMag / Batman-for-Facebook.JPG"; Img.AlternateText = "Test Image"; Div.Controls.Add (img); Div.Controls.Add (ParseControl (String.Format ("& amp; nbsp;" + "{0}", Reader. GetString (0))); Div.Style ["Clear"] = "Both"; Test1.Controls.Add (div); }    

yes

  & lt; Div runat = "server" & gt; & Lt; / Div & gt;   

This will make server-side controls and you can generate it in code using

  var myDiv = new HtmlGenericControl ("div"); Edit: The one you are generating is Server Side Control, there is no need to add  runat = "server" .  

Edit per comment:

  & lt; Div onclick = "warning ('hello')" runat = "server" & gt; & Lt; / Div & gt;   

or

  var myDiv = new HtmlGenericControl ("div"); MyDiv.Attributes.Add ("OnClick", "Alert ('Hello'););    

Comments