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


    简单记录一下这个方法: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);");
            }
        }
    }

    。。。。

  • 相关阅读:
    帮助理解Docker,生动装逼介绍Docker
    Java 最常见 200+ 面试题 + 全解析
    CentOS7.0 yum安装 docker
    集合总结
    C#复习笔记
    match方法的使用
    偏函数
    通用装饰器
    装饰器修饰带参数的功能函数
    多个装饰器的使用
  • 原文地址:https://www.cnblogs.com/mingmingruyuedlut/p/2954995.html
Copyright © 2020-2023  润新知