Apply style to div tag.
-
Hi All, I am creating div at runtime and I have to apply style to it but I am not getting how to do it. I have created div tag like this: HtmlGenericControl divtest = new HtmlGenericControl(); and now I want to apply the following style: text-align: right; display: none; overflow: auto; scrollbar-face-color : #ffffff; scrollbar-highlight-color : #000000; scrollbar-3dlight-color : #cccccc; scrollbar-shadow-color : #000000; scrollbar-darkshadow-color : #cccccc; scrollbar-track-color : #cccccc; scrollbar-arrow-color : #000000; Please help me with this... Thanks in advance...
ASP.NET 2.0 wrote:
now I want to apply the following style:
divtest.Attributes.Add("style","text-align: right;display: none;overflow: auto;........... ");
bEst rEgard pAthan
please don't forget to vote on the post that helped you.
-
Hi All, I am creating div at runtime and I have to apply style to it but I am not getting how to do it. I have created div tag like this: HtmlGenericControl divtest = new HtmlGenericControl(); and now I want to apply the following style: text-align: right; display: none; overflow: auto; scrollbar-face-color : #ffffff; scrollbar-highlight-color : #000000; scrollbar-3dlight-color : #cccccc; scrollbar-shadow-color : #000000; scrollbar-darkshadow-color : #cccccc; scrollbar-track-color : #cccccc; scrollbar-arrow-color : #000000; Please help me with this... Thanks in advance...
If you are adding styles I would suggest using a CSS class rather than explicity adding it in code, it makes it more managable and reusable divtest.attributes.add("class", "myclass") and then define in a CSS file myclass with the attributes you want div.myclass { text-align: right; display: none; overflow: auto; scrollbar-face-color : #ffffff; scrollbar-highlight-color : #000000; scrollbar-3dlight-color : #cccccc; scrollbar-shadow-color : #000000; scrollbar-darkshadow-color : #cccccc; scrollbar-track-color : #cccccc; scrollbar-arrow-color : #000000; } It also means you dont have to recompile if you need to make changes. However, if you do need to apply it directly in code for some reason then i would suggest using the built in style property which can be strongly typed which is always nice, as follows divtest.Style.Add(HtmlTextWriterStyle.TextAlign, "right") or for ones which are not included in the strongly typed list use divtest.Style.Add("scrollbar-face-color", "#000000") Hope that helps
-
ASP.NET 2.0 wrote:
now I want to apply the following style:
divtest.Attributes.Add("style","text-align: right;display: none;overflow: auto;........... ");
bEst rEgard pAthan
please don't forget to vote on the post that helped you.
Thanks for the reply sir, but its not working. I have to actually show this div tag on onmouseover so I am using Ajax HoverMenuExtender which is also created runtime. The problem is that I am having GridView control which is created runtime and there are 2 Template column and others are BoundField Columns. Template Column is Checkbox and Linkbutton column and on the linkbutton mouseover I have to show the summary. I dont know where I have going wrong??? Thanks again...
-
If you are adding styles I would suggest using a CSS class rather than explicity adding it in code, it makes it more managable and reusable divtest.attributes.add("class", "myclass") and then define in a CSS file myclass with the attributes you want div.myclass { text-align: right; display: none; overflow: auto; scrollbar-face-color : #ffffff; scrollbar-highlight-color : #000000; scrollbar-3dlight-color : #cccccc; scrollbar-shadow-color : #000000; scrollbar-darkshadow-color : #cccccc; scrollbar-track-color : #cccccc; scrollbar-arrow-color : #000000; } It also means you dont have to recompile if you need to make changes. However, if you do need to apply it directly in code for some reason then i would suggest using the built in style property which can be strongly typed which is always nice, as follows divtest.Style.Add(HtmlTextWriterStyle.TextAlign, "right") or for ones which are not included in the strongly typed list use divtest.Style.Add("scrollbar-face-color", "#000000") Hope that helps
Thanks for the reply sir, but its not working. I have to actually show this div tag on onmouseover so I am using Ajax HoverMenuExtender which is also created runtime. The problem is that I am having GridView control which is created runtime and there are 2 Template column and others are BoundField Columns. Template Column is Checkbox and Linkbutton column and on the linkbutton mouseover I have to show the summary. I dont know where I have going wrong??? Thanks again...
-
Thanks for the reply sir, but its not working. I have to actually show this div tag on onmouseover so I am using Ajax HoverMenuExtender which is also created runtime. The problem is that I am having GridView control which is created runtime and there are 2 Template column and others are BoundField Columns. Template Column is Checkbox and Linkbutton column and on the linkbutton mouseover I have to show the summary. I dont know where I have going wrong??? Thanks again...
Ok. tell me where have you used my code? please post your bEst rEgard pAthan
please don't forget to vote on the post that helped you.
-
Thanks for the reply sir, but its not working. I have to actually show this div tag on onmouseover so I am using Ajax HoverMenuExtender which is also created runtime. The problem is that I am having GridView control which is created runtime and there are 2 Template column and others are BoundField Columns. Template Column is Checkbox and Linkbutton column and on the linkbutton mouseover I have to show the summary. I dont know where I have going wrong??? Thanks again...
Both sets of code provided as answers will work, and are valid ways of doing it, but you seem to have a specific implementation issue here. Can you please just let me know what the issue is that you are having - does the div show? Is it just missing the style information?
-
Both sets of code provided as answers will work, and are valid ways of doing it, but you seem to have a specific implementation issue here. Can you please just let me know what the issue is that you are having - does the div show? Is it just missing the style information?
No I can see the style when I right click view source. The problem is I have to show this div tag only on mouse over div its showing all. here is the code: I have create a class GridViewTemplate public class GridViewTemplate: System.Web.UI.Page, ITemplate { ListItemType templateType; string columnName; private Int32 RowItems; ArrayList arrgvCompanyName; public GridViewTemplate(ListItemType type, string colname) { templateType = type; columnName = colname; } public GridViewTemplate(ListItemType type, string colname, ArrayList gvCompanyName) { templateType = type; columnName = colname; arrgvCompanyName = gvCompanyName; } public void InstantiateIn(System.Web.UI.Control container) { Literal lc = new Literal(); LinkButton lb = new LinkButton(); CheckBox chk = new CheckBox(); TextBox tb1 = new TextBox(); AjaxControlToolkit.HoverMenuExtender hme2 = new AjaxControlToolkit.HoverMenuExtender(); Panel PopupMenu = new Panel(); HtmlGenericControl divtest = new HtmlGenericControl(); HtmlImage imgTop = new HtmlImage(); HtmlImage imgBottom = new HtmlImage(); switch (templateType) { case ListItemType.Header: lc.Text = "" + columnName + ""; if (columnName == "CheckAll") { container.Controls.Add(chk); } container.Controls.Add(lc); break; case ListItemType.Item: //container.Controls.Add(tb1); if (columnName == "CheckAll") { container.Controls.Add(chk); } //else if(columnName="CompanyName") //{ //} else { if (arrgvCompanyName.Count > 0) { columnName = arrgvCompanyName[RowItems].ToString(); lb.Text = columnName; lb.CommandName = "cmd"; hme2.TargetControlID = "lb"; hme2.PopupControlID = "PopupMenu"; //hme2.PopupPosition = Center; hme2.OffsetX = 60; hme2.OffsetY = -15; hme2.PopDelay = 10;
-
Ok. tell me where have you used my code? please post your bEst rEgard pAthan
please don't forget to vote on the post that helped you.
No I can see the style when I right click view source. The problem is I have to show this div tag only on mouse over div its showing all. here is the code: I have create a class GridViewTemplate public class GridViewTemplate: System.Web.UI.Page, ITemplate { ListItemType templateType; string columnName; private Int32 RowItems; ArrayList arrgvCompanyName; public GridViewTemplate(ListItemType type, string colname) { templateType = type; columnName = colname; } public GridViewTemplate(ListItemType type, string colname, ArrayList gvCompanyName) { templateType = type; columnName = colname; arrgvCompanyName = gvCompanyName; } public void InstantiateIn(System.Web.UI.Control container) { Literal lc = new Literal(); LinkButton lb = new LinkButton(); CheckBox chk = new CheckBox(); TextBox tb1 = new TextBox(); AjaxControlToolkit.HoverMenuExtender hme2 = new AjaxControlToolkit.HoverMenuExtender(); Panel PopupMenu = new Panel(); HtmlGenericControl divtest = new HtmlGenericControl(); HtmlImage imgTop = new HtmlImage(); HtmlImage imgBottom = new HtmlImage(); switch (templateType) { case ListItemType.Header: lc.Text = "" + columnName + ""; if (columnName == "CheckAll") { container.Controls.Add(chk); } container.Controls.Add(lc); break; case ListItemType.Item: //container.Controls.Add(tb1); if (columnName == "CheckAll") { container.Controls.Add(chk); } //else if(columnName="CompanyName") //{ //} else { if (arrgvCompanyName.Count > 0) { columnName = arrgvCompanyName[RowItems].ToString(); lb.Text = columnName; lb.CommandName = "cmd"; hme2.TargetControlID = "lb"; hme2.PopupControlID = "PopupMenu"; //hme2.PopupPosition = Center; hme2.OffsetX = 60; hme2.OffsetY = -15; hme2.PopDelay = 10;
-
No I can see the style when I right click view source. The problem is I have to show this div tag only on mouse over div its showing all. here is the code: I have create a class GridViewTemplate public class GridViewTemplate: System.Web.UI.Page, ITemplate { ListItemType templateType; string columnName; private Int32 RowItems; ArrayList arrgvCompanyName; public GridViewTemplate(ListItemType type, string colname) { templateType = type; columnName = colname; } public GridViewTemplate(ListItemType type, string colname, ArrayList gvCompanyName) { templateType = type; columnName = colname; arrgvCompanyName = gvCompanyName; } public void InstantiateIn(System.Web.UI.Control container) { Literal lc = new Literal(); LinkButton lb = new LinkButton(); CheckBox chk = new CheckBox(); TextBox tb1 = new TextBox(); AjaxControlToolkit.HoverMenuExtender hme2 = new AjaxControlToolkit.HoverMenuExtender(); Panel PopupMenu = new Panel(); HtmlGenericControl divtest = new HtmlGenericControl(); HtmlImage imgTop = new HtmlImage(); HtmlImage imgBottom = new HtmlImage(); switch (templateType) { case ListItemType.Header: lc.Text = "" + columnName + ""; if (columnName == "CheckAll") { container.Controls.Add(chk); } container.Controls.Add(lc); break; case ListItemType.Item: //container.Controls.Add(tb1); if (columnName == "CheckAll") { container.Controls.Add(chk); } //else if(columnName="CompanyName") //{ //} else { if (arrgvCompanyName.Count > 0) { columnName = arrgvCompanyName[RowItems].ToString(); lb.Text = columnName; lb.CommandName = "cmd"; hme2.TargetControlID = "lb"; hme2.PopupControlID = "PopupMenu"; //hme2.PopupPosition = Center; hme2.OffsetX = 60; hme2.OffsetY = -15; hme2.PopDelay = 10;
From looking at the code the obvious is that you are not setting the ID property of the panel which you want to show, you are setting TargetPopupId to be 'PopupMenu' but that is the name of the object, not the Id of the control which you want to use, try adding the line PopupMenu.Id = "PopupMenu" It is not the div which you are trying to hide or display on the mouseover but the panel also, the div is just a control within the panel. Really you should set the Id property for all controls you add on the page, especially if they are containers. Also im not sure what the default is but you should perhaps specifty the type of generic html control in the constuctor HtmlGenericControl divtest = new HtmlGenericControl("Div");
-
From looking at the code the obvious is that you are not setting the ID property of the panel which you want to show, you are setting TargetPopupId to be 'PopupMenu' but that is the name of the object, not the Id of the control which you want to use, try adding the line PopupMenu.Id = "PopupMenu" It is not the div which you are trying to hide or display on the mouseover but the panel also, the div is just a control within the panel. Really you should set the Id property for all controls you add on the page, especially if they are containers. Also im not sure what the default is but you should perhaps specifty the type of generic html control in the constuctor HtmlGenericControl divtest = new HtmlGenericControl("Div");
Thanks for the reply sir but I have tried that also, but its not working... :(