c# webform js文件获取客户端控件,后台cs获取前台客户端控件的值,c#和js的交互
aspx文件:
Hidden2为客户端控件
给Hidden2控件赋值
js文件
取出Hidden2控件的值
cs文件
Hidden2为客户端控件
- <%@ 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" >
- <script language="JavaScript" type="text/javascript" src="Move.js"></script>
- <head runat="server">
- <title>无标题页</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <input name="Hidden_name" id="Hidden2" type="hidden" value="" />
- <input id="btn" onclick="a()" type=button value="按下" />
- <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
- </form>
- </body>
- </html>
给Hidden2控件赋值
js文件
- // JScript 文件
- function a()
- {
- document.getElementById("Hidden2").value="456";
- }
取出Hidden2控件的值
cs文件
- using System;
- using System.Data;
- using System.Configuration;
- 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)
- {
- Response.Write(Request.Form["Hidden_name"].ToString());
- }
- }