web页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function doTest() {
var obj = document.getElementById("CSharpActiveX");
//obj.Test();
var path = obj.prop; //activex控件属性
//document.getElementById("<%= Label1.ClientID %>").value = path;
document.getElementById("<%= TextBox1.ClientID %>").value = path;
// document.getElementById("<%= hid1.ClientID %>").value = path;
}
</script></head>
<body >
<form id="form1" runat="server">
<div>
<object id="CSharpActiveX" classid="clsid:834545F9-0DDB-4e91-9FE8-F08DFA6D126C">
</object>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label" Width="500" Height="500"></asp:Label>
<asp:HiddenField runat="server" ID="hid1"></asp:HiddenField>
<input type="button" value="测试" onclick="javascript:doTest()" />
</div>
</form>
</body>
</html>
后台: protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>doTest();</script>");
}
问题:
1.我在后台执行js把值赋给HiddenField 貌失不能赋值(执行顺序是怎么样的?先执行服务器控件,还是js? obj为null)。2.("<%= TextBox1.ClientID %>")这个只能给TextBox用么?为什么Lablel,HiddenField 都赋值不了。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function doTest() {
var obj = document.getElementById("CSharpActiveX");
//obj.Test();
var path = obj.prop; //activex控件属性
//document.getElementById("<%= Label1.ClientID %>").value = path;
document.getElementById("<%= TextBox1.ClientID %>").value = path;
// document.getElementById("<%= hid1.ClientID %>").value = path;
}
</script></head>
<body >
<form id="form1" runat="server">
<div>
<object id="CSharpActiveX" classid="clsid:834545F9-0DDB-4e91-9FE8-F08DFA6D126C">
</object>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label" Width="500" Height="500"></asp:Label>
<asp:HiddenField runat="server" ID="hid1"></asp:HiddenField>
<input type="button" value="测试" onclick="javascript:doTest()" />
</div>
</form>
</body>
</html>
后台: protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>doTest();</script>");
}
问题:
1.我在后台执行js把值赋给HiddenField 貌失不能赋值(执行顺序是怎么样的?先执行服务器控件,还是js? obj为null)。2.("<%= TextBox1.ClientID %>")这个只能给TextBox用么?为什么Lablel,HiddenField 都赋值不了。
可以用绑定的方式"<%# TextBox1.ClientID %>,然后页面中调用下Page.DataBind();