当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > js获取.aspx页面里面的服务器控件和.ascx中的服务器控件值

ASP.NET
asp.net DataFormatString格式化GridView
ASP.NET生成Google网站地图的代码
ASP.NET(C#)中遍历所有控件
ASP.NET 程序优化 小结
asp.net 自制的单选、多选列表实现代码
ASP.NET 前台javascript与后台代码调用
ASP.NET FileUpload 上传图片实例
TextBox的宽度随输入的文本的大小而改变的js代码
VisualStudio 2008中常用快捷键
ASP.NET开发者使用jQuery应该了解的几件事情
xml 文件的创建和读取代码
ASP.NET 页面之间传递参数方法汇总
ASP.NET效率陷阱之——Attributes
C#.NET中关于结构与类之间的区别
ASP.NET 2.0中发送电子邮件剖析之一
ASP.NET四种页面导航方式之比较与选择
错误处理
ASP.NET底层架构探索之再谈.NET运行时(一)
认识Web.config文件
解读C#中的正则表达式

ASP.NET 中的 js获取.aspx页面里面的服务器控件和.ascx中的服务器控件值


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-11   浏览: 159 ::
收藏到网摘: n/a

用js获取.ascx控件中服务器控件值时首先要得到服务器控件的ClientID再加上.ascx页面里面的服务器空间ID并用"_"连接 A.aspx页面
复制代码 代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="A.aspx.cs" Inherits="OrderManage_A" %>
<%@ Register Src="../UserControl/CtrlCalendar.ascx" TagName="CtrlCalendar" TagPrefix="uc1" %>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<script language="javascript" type="text/javascript">
function GetValue()
{
var txpro=document.getElementById('<%=txtProvider_rename.ClientID %>');
//用js获取服务器控件的值时首先要得到服务器控件的ClientID
var txdat=document.getElementById('<%=txtCheckIn.ClientID %>'+"_txtDateVal");
//用js获取.ascx控件中服务器控件值时首先要得到服务器控件的ClientID再加上.ascx页面里面的服务器空间ID并用"_"连接
txpro.value=txdat.value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<tr>
<td align="right" bgcolor="#dee5fa">入住日期</td>
<td align="left" bgcolor="#dee5fa"><uc1:CtrlCalendar ID="txtCheckIn" runat="server" /></td>
</tr>
<tr>
<td align="right" bgcolor="#dee5fa" onclick="GetValue()"><asp:TextBox ID="txtProvider_rename" runat="server" Width="312px"></asp:TextBox></td>
</tr>
</div>
</form>
</body>
</html>

CtrlCalendar.ascx
复制代码 代码如下:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CtrlCalendar.ascx.cs" Inherits="CtrlCalendar" %>
<table id="Table1" style="HEIGHT: 24px" cellspacing="0" cellpadding="0" width="100" border="0">
<tr>
<td style="WIDTH: 81px"><font face="宋体">
<asp:textbox id="txtDateVal" Width="84px" runat="server" BorderStyle="Groove"></asp:textbox></font></td>
<td><div id="Div_imgCanlendar"><font face="宋体"><img id="imgCanlendar" style="CURSOR: hand" alt="" src="/upload/tech/20091011/20091011144046_ec8956637a99787bd197eacd77acce5e.gif" runat="server" /></font></div></td>
</tr>
</table>