You can achieve this by using the Browser
property of the HttpRequest
object.
Your page can either have both user-controls sited at design time, then at run time, you inspect the Request.Browser
property to determine the client's browser and programmatically hide the user-control you don't want the user to see.
Alternatively, you can instantiate and render the correct user-control (again, after inspecting the Request.Browser
property) purely from your server-side code.
For example, running the following code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Request.Browser.Type.ToString());
}
}
In a "standard" ASPX page displays:
IE7
when run in Internet Explorer 7, and:
Firefox3.5.3
(when run in Firefox)
So, you could have code something like the following in the web-page that you want to add this functionality to:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Browser.Type.ToString().ToLower().Contains("ie"))
{
// User's browser is Internet Explorer.
// Let's hide UserControl1 but display UserControl1
WebUserControl1.Visible = false;
WebUserControl2.Visible = true;
}
else
{
// User's browser is something other than Internet Explorer.
// Let's hide UserControl2 but display UserControl1.
WebUserControl1.Visible = true;
WebUserControl2.Visible = false;
}
}
}