You are detecting the user-agent with javascript. But, being a server control, the MobileAd.ascx
got executed before javascript could execute. You should do it on server-side by checking Request.UserAgent
or Request.Browser.IsMobileDevice
. If the sole purpose of the property AdType
is to just hold user-agent type, you can remove it and try modifying your Page_Load
method like this:
protected void Page_Load(object sender, EventArgs e)
{
string html = null;
if (Request.Browser.IsMobileDevice)
{
html = "Mobile Ad Code";
}
else
{
html = "Tablet or Desktop Ad Code";
}
divHtml.InnerHtml = html;
}