您的位置:首页 > Web前端 > JavaScript

Asp.Net 用后台代码给Server控件添加Client端JS方法

2013-03-13 08:17 796 查看
简单记录一下这个方法:Asp.Net 用后台代码给Server控件添加Client端JS方法

前台代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.9.0.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="EricSun" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="EricSun" />
</div>
</form>
</body>
</html>

<script type="text/javascript">
function RadioBtnOnClick(obj) {
$("#<%=TextBox1.ClientID%>").attr('disabled', 'disabled');
}
</script>


后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.RadioButton1.InputAttributes.Add("OnClick", "RadioBtnOnClick(this);");
this.RadioButton2.InputAttributes.Add("OnClick", "RadioBtnOnClick(this);");
}
}
}


。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: