日期:2014-05-18 浏览次数:20388 次
<script type="text/javascript"> function newpic() { var bd = document.getElementById("bigimage").href = "Images/3.jpg" var bs = document.getElementById("smallimage").src = "Images/4.jpg" } </script>
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>newpic();</script>");
------解决方案--------------------
在页面上放个控件,比如literal,把你要生成的js在服务端包装好,ru:
public static string GetJS(string id) { StringBuilder sb = new StringBuilder(); sb.Append("<script type=\"text/javascript\">"); sb.Append("function OpenDialog()"); sb.Append("{"); sb.Append("var users=window.showModalDialog('SelectUsers.aspx','0','dialogWidth:300px;dialogHeight:450px');"); sb.Append(string.Format("document.getElementById('{0}').value=users;",controlid)); sb.Append("}"); sb.Append("</script>"); return sb.ToString(); }
------解决方案--------------------
.aspx中:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<img id="smallimage" src="" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
.cs中:
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder strSb = new StringBuilder();
string strPic= "Images/4.jpg";
strSb.Append("<script type='text/javascript'>");
strSb.Append("document.getElementById('smallimage').src =");
strSb.Append(strPic);
strSb.Append("</script>");
}