应该注意一点就是在客户端代码中,要使用控件名称的时候,就应该在
cboSite.Atributes.add("ID","cboSite");

HtmlInputButton btnGo;
HtmlSelect cboWebSite;
HtmlSelect cboSiteLists;

// 为加入客户端静态代码而准备的
private const string ByeByeIncludeScriptKey = "myByeByeIncludeScript";
private string EmbeddedScriptFormat =
"<script language=javascript>function ByeBye(){alert('Bye Bye'); }</script> ";

private void NavigateAndSearch_PreRender(object sender , System.EventArgs e )

{
RegisterCommonScript();
}
public NavigateAndSearch()

{
this.PreRender += new EventHandler(NavigateAndSearch_PreRender);
}


protected void RegisterCommonScript()

{
//Embedded Client Script
if(!Page.IsClientScriptBlockRegistered(ByeByeIncludeScriptKey))
Page.RegisterClientScriptBlock(ByeByeIncludeScriptKey,
EmbeddedScriptFormat);

}


protected override void CreateChildControls ()

{
int i,j ;
ListItem li;
cboWebSite = new HtmlSelect ();
cboSiteLists =new HtmlSelect();
btnGo =new HtmlInputButton ();
btnGo.Value=" 打开 ";
btnGo.Attributes.Add("onClick","onClick()");
//取出所有网站
SPSite mySite = new SPSite(text);
SPWeb web = mySite.OpenWeb();
for (i=0;i<web.Webs.Count;i++)

{
SPWeb myweb = web.Webs[i];
li=new ListItem ();
li.Text=myweb.Title.ToString();
li.Value=myweb.Url.ToString();
cboWebSite.Items.Add(li);
}

cboWebSite.Attributes.Add("onChange","onComboChange()");
cboWebSite.Attributes.Add ("ID","cboSite");
cboSiteLists.Attributes.Add("ID","cboList");
cboSiteLists.Attributes.Add("style","140");
cboWebSite.Attributes.Add("style","140");
Controls.Add(cboWebSite);
Controls.Add(cboSiteLists );
Controls.Add(btnGo);

//需要在这里改变一个客户端的代码EmbeddedScriptFormat
EmbeddedScriptFormat = "<script language=javascript>";
EmbeddedScriptFormat += " function onComboChange(){";
EmbeddedScriptFormat += "switch(document.all.cboSite.options[document.all.cboSite.selectedIndex].text)";
EmbeddedScriptFormat +="{";
for (i=0;i<web.Webs.Count;i++)

{
EmbeddedScriptFormat += "case '" + web.Webs[i].Title.ToString() + "':";
SPSite llSite=new SPSite(web.Webs[i].Url);
SPWeb llweb=llSite.OpenWeb();
for (j=0;j<llweb.Lists.Count;j++)

{
SPList mylist=llweb.Lists[j];
if (j==0)

{
EmbeddedScriptFormat += " document.all.cboList.options[" + j.ToString() + "]=new Option('" +
mylist.Title.ToString() + "','" + mylist.DefaultViewUrl + "',true,false);";
}
else

{
EmbeddedScriptFormat += " document.all.cboList.options[" + j.ToString() + "]=new Option('" +
mylist.Title.ToString() + "','" + mylist.DefaultViewUrl + "',false,false);";
}
}
EmbeddedScriptFormat +="break;";
}
EmbeddedScriptFormat +="}}";
EmbeddedScriptFormat += "function onClick(){";
EmbeddedScriptFormat += " window.open('http://portol" +
"' + document.all.cboList.options[document.all.cboList.selectedIndex].value)";
EmbeddedScriptFormat += "}</script>";
}