My website was built using Visual Studio Pro 2010 with a back-end on Windows Server 2008 R2, SQL Server 2008 R2, and IIS 7. The .NET Framework version used is 4.0.
The Dropdownlist on my site works fine in Internet Explorer, but it displays strange characters in Chrome and Firefox. It seems like the output is being encoded incorrectly. I tried implementing a code to fix this issue, but it doesn't seem to be working as expected. See the code snippet below for reference.
I also attempted to address the problem by configuring legacy settings. As a result, I added the following line to the web.config file:
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
ASP.NET HTML TAG
<asp:DropDownList ID="JobCategoryList" runat="server" OnDataBound="SortHTML">
</asp:DropDownList>
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DisplayCategories();
}
}
private void DisplayCategories()
{
_objCategories.getJobCategories();
JobCategoryList.DataSource = _objCategories.JobCategoriesDS.Tables["GetJobCategories"];
JobCategoryList.DataTextField = "CategoryName";
JobCategoryList.DataValueField = "Id";
JobCategoryList.DataBind();
}
protected void SortHTML(object sender, EventArgs e)
{
foreach (ListItem item in ((DropDownList)sender).Items)
{
item.Text = Server.HtmlDecode(item.Text);
}
}