后台.cs调用前台JS的问题
<%@ 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>Untitled Page</title> <script type="text/javascript"> function UploadClick() { var i = 1 ; var j; var k; var aCannel; var aIP; aCannel = document.getElementById("ListCannel") aIP = document.getElementById("ListIP") var ds0 = aCannel[0].value; var dm0 = aIP[0].value; var ds1 = aCannel[1].value; var dm1 = aIP[1].value; var ds2 = aCannel[2].value; var dm2 = aIP[2].value; var mm = parseInt(ds0); i=document.getElementById("OBJECT1").Initvideo(ds0, dm0,0); j=document.getElementById("OBJECT2").Initvideo(2, "192.168.3.102",0); k=document.getElementById("OBJECT3").Initvideo(3, "192.168.3.102",0); alert(k) ; } function UnloadClick(){ var i; var j; var k; i=document.getElementById("OBJECT1").DeInitvideo(); j=document.getElementById("OBJECT2").DeInitvideo(); k=document.getElementById("OBJECT3").DeInitvideo(); alert(k) ; } function StartRecordClick() { var i; var j; var k; var aCannel; var aIP; aCannel = document.getElementById("ListCannel") var ds0 = aCannel[0].value; var ds1 = aCannel[1].value; var ds2 = aCannel[2].value; i=document.getElementById("OBJECT1").Videotape(1); j=document.getElementById("OBJECT2").Videotape(2); k=document.getElementById("OBJECT3").Videotape(3); alert(k); } function EndRecordClick() { var i; var j; var k; var aCannel; var aIP; aCannel = document.getElementById("ListCannel") var ds0 = aCannel[0].value; var ds1 = aCannel[1].value; var ds2 = aCannel[2].value; i=document.getElementById("OBJECT1").DeVideotape(1); j=document.getElementById("OBJECT2").DeVideotape(2); k=document.getElementById("OBJECT3").DeVideotape(3); alert(k); } </script></head><body> <form id="form1" runat="server"> <asp:Button ID="button5" Text="测试" runat="server" /> <asp:DropDownList ID="ListCannel" runat="server" Width="100px"> </asp:DropDownList> <asp:DropDownList ID="ListIP" runat="server" Width="120px"> </asp:DropDownList> <div> <span style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid; border-bottom: gray 1px solid;"> <object id="OBJECT1" width="400" height="300" classid="CLSID:D3170B47-FEDD-4BC4-AF03-004B5F253EC4"> </object> </span><span style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid; border-bottom: gray 1px solid;"> <object id="OBJECT2" width="400" height="300" classid="CLSID:D3170B47-FEDD-4BC4-AF03-004B5F253EC4"> </object> </span><span style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid; border-bottom: gray 1px solid;"> <object id="OBJECT3" width="400" height="300" classid="CLSID:D3170B47-FEDD-4BC4-AF03-004B5F253EC4"> </object> </span> </div> </form> <p> <input id="Button1" type="button" value="开启视频" onclick="UploadClick()" /></p> <p> <input id="Button2" type="button" value="关闭视频" onclick="UnloadClick()" /></p> <p> <input id="Button3" type="button" value="开始录像" onclick="StartRecordClick()" /></p> <p> <input id="Button4" type="button" value="结束录像" onclick="EndRecordClick()" /></p></body></html>
using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Collections;using System.Collections.Generic;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Util.Util.alertMsg("123"); //List<string> dinosaurs2 = new List<string>(); List<int> dinosaurs1 = new List<int>(); dinosaurs1.Add(1); dinosaurs1.Add(2); dinosaurs1.Add(3); //dinosaurs2.Add("192.168.3.111"); //dinosaurs2.Add("192.168.3.111"); //dinosaurs2.Add("192.168.3.111"); ListCannel.DataSource = dinosaurs1; //ListIP.DataSource = dinosaurs2; ListCannel.DataBind(); //ListIP.DataBind(); //ListCannel.Items.Add(1); //ListCannel.Items.Add(2); //ListCannel.Items.Add(3); ListIP.Items.Add("192.168.3.111"); ListIP.Items.Add("192.168.3.111"); ListIP.Items.Add("192.168.3.111"); ////this.button5.Attributes.Add("OnClick", "javascript:UploadClick(" + dinosaurs1 + ", " + dinosaurs2 + ")"); ////this.button5.Attributes.Add("OnClick", "javascript:UploadClick('aa')"); //this.button5.Attributes.Add("OnClick", "javascript:UploadClick(" + dinosaurs1 + ")"); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "javascript", "UploadClick();", true); } }}
Page.ClientScript.RegisterStartupScript(typeof(Page), "", "<script>setTimeout(\"UploadClick()\", 2000);</script>");