Then you need to use Ajax WebMethod.
This the menu that i have added from code behind into some div tag.
<div id="div1" runat="server">
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("<ul id='menu' runat='server'>" +
"<li>India</li>" +
"<li>Germany</li>" +
"<li>US</li>"
+ "</ul>");
this.div1.InnerHtml = sb.ToString();
}
Now i cannot get the menu id from the code behind so i need to use jQuery with AjaxWebMethod to set the additional css from the database.
jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$.ajax({
type: "POST",
url: "Default2.aspx/GetStyle",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$('#menu').css('font-weight', response.d)
},
failure: function (response) {
alert(response.d);
}
});
</script>
Namespace
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
WebMethod
[System.Web.Services.WebMethod]
public static string GetStyle()
{
string style = string.Empty;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT [fontweight] FROM tblStyles", con))
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
style = sdr[0].ToString();
con.Close();
}
}
return style;
}
SQL
CREATE TABLE [tblStyles](
[Id] [int] IDENTITY(1,1) NOT NULL,
[fontweight] [varchar](50) NOT NULL
) ON [PRIMARY]
GO
INSERT INTO [tblStyles]
([fontweight])
VALUES
('bold')
GO
Screenshot
