Материал из .Net Framework эксперт
Go to home page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="HomePage" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input runat="server" type="button" id="HomePageButton" value="Set home page" />
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Reflection;
using System.IO;
public partial class HomePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string HOMEPAGE = "http://www.nfex.ru";
HttpBrowserCapabilities caps = Request.Browser;
if (caps.IsBrowser("IE") && (caps.MajorVersion > 5 ||
caps.MajorVersion == 5 && caps.MinorVersion >= 5))
{
HomePageButton.Disabled = false;
HomePageButton.Attributes["onclick"] = "SetHomePage(this)";
Type t = this.GetType();
if (!Page.ClientScript.IsClientScriptBlockRegistered(t, "SetHomePage"))
{
string js = BuildScriptCode(HOMEPAGE);
Page.ClientScript.RegisterClientScriptBlock(t, "SetHomePage", js, true);
}
}
else
HomePageButton.Disabled = true;
}
private string BuildScriptCode(string url)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("function SetHomePage(obj) {");
sb.AppendLine(" obj.style.behavior=\"url(#default#homepage)\";");
sb.AppendFormat(" obj.setHomePage(\"{0}\");\r\n", url);
sb.AppendLine("}");
return sb.ToString();
}
}