js如何给C#控件赋值
来源:互联网 发布:华东理工网络教育 编辑:程序博客网 时间:2024/05/16 18:42
有时候在C#环境里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>无标题页</title>
<script type="text/javascript">
function fz(){
var std = "2";
alert(std);
document.getElementById('HiddenField1').value=std;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
项目中有个小功能,在Js中修改一个服务器标签的值,如 document.getElementById("lblClothIndex").innerHTML = result;(比如由“1”修改成“2”),可是在后台通过this.lblClothIndex.Text获得的还是"1"这个老值。后来发现通过调用隐藏控件的方法可以获得最新值,代码如下:
1. 添加一个隐藏控件 <asp:HiddenField ID="HiddenField1" runat="server" Value="" />
<asp:TextBox ID="TextBox1" runat="server">0</asp:TextBox>
<a href="#" onclick="fz()">赋值</a>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
2. 用JS为服务器标签赋值的时候也给隐藏控件赋值
3. 在后台通过 this.HiddenField1.Value代码获得最新值
</div>
</form>
</body>
</html>
后台代码
using System;
using System.Collections;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = HiddenField1.Value;
}
}
来自:http://www.ok22.org
- js如何给C#控件赋值
- JS 给c#控件赋值
- js如何给赋值
- c#如何在线程给中控件赋值
- C#多线程给控件赋值 抛异常
- js给服务器控件赋值注意事项
- Js 给asp.net 控件赋值
- C#利用API给其它线程的各种控件赋值
- C# winform在线程中给控件赋值
- js中子页面给父页面的控件赋值
- 给控件赋值
- jQuery给控件赋值....
- jQuery给控件赋值
- jQuery给控件赋值....
- 批量给控件赋值
- jQuery给控件赋值....
- jQuery给控件赋值
- jQuery给控件赋值
- POJO的概念
- C# 自定义控件(二) 新闻控件的优化
- Windows CE Notification API的使用方法
- BW:EDW——一次小小的探讨
- PrepareCall() 执行存储过程
- js如何给C#控件赋值
- ssh junit4报错
- SqlServer 2005 全文索引 实例
- NT是怎么载入NTLDR的 NT引导研究 ( MBR->DBR->NTLDR )
- GCC-3.4.6源代码学习笔记 (103)
- ZTSF知多少?
- Studying note of GCC-3.4.6 source (103)
- 260Il Gioco dell'X
- ARM ADS集成开发环境的使用