日期:2014-05-17 浏览次数:20498 次
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <script type="text/javascript"> function winid() { document.getElementById("hf").value="5"; alert( document.getElementById("hf").value); } </script> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:HiddenField ID="hf" runat="server" /> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Literal l = new Literal(); l.Text = "<script>winid()</script>"; this.Page.Controls.Add(l); string ss= hf.Value.ToString();//这个value值怎么总是空 } }
Page.RegisterStartupScript("", "<script>winid();<"+"/script>");
------解决方案--------------------
厄?lz用literal类了?
我感觉写的没错呀也?怎么会空值哩?单步吧...
------解决方案--------------------
protected void Button1_Click(object sender, EventArgs e)
{
Literal l = new Literal();
l.Text = "<script>winid()</script>";
this.Page.Controls.Add(l);
string ss= hf.Value.ToString();//这个value值怎么总是空
}
你是想後臺 調用 前臺 腳本 吧。 這樣調用貌似錯的哦。