I have an IF/ELSE condition in my C# code (using webforms) and I want to use ClientScript.RegisterClientScriptBlock to change an anchor tag class
email = Business.Core.Profiles.Email.SetEmailAlertProfile(base.companyId, type);
// Email obj == null means no alert data for advertiser with this ID.
if (email == null)
{
EmailAction = "add";
lblEmailText.Text = "Add to Email Alerts";
//Change Anchor class to show remove image
//ClientScript.RegisterClientScriptBlock(typeof(string), "ChangeAnchorClass", "<script>$('.jsPopUp btnAddEList active').addClass('jsPopUp btnRemoveEList active');</script>");
}
else
{
EmailAction = "delete";
lblEmailText.Text = "Remove from Emails";
//Change Anchor class to show remove image
ClientScript.RegisterClientScriptBlock(typeof(string), "ChangeAnchorClass", "<script>document.getElementById('hrefEmail').className = 'MyClass';</script>");
}
My ELSE condition gives me the following error:
Microsoft JScript runtime error: Unable to set value of the property 'className': object is null or undefined
I have used client script in my project elsewhere but it is not working here.
Additional information:
This code is in a method which is called on page load. Don't know if that makes a difference.