C# 后台调用前台的JS方法 以及常用的代码片断

-------------------------------------------------后台调用前台的JS方法-------------------------------------------------------  ClientScript.RegisterStartupScript(this.GetType(), "s", "<script>method();</script>");
 if (confirm("添加成功!是否继续添加?")==true) //弹出确认框

页面:
 function method()
     {
         if (confirm("添加成功!是否继续添加?")==true)
         {
            ClearInput();
         }else
         {
          closeWin();
         }
      }


-----------输入框不可写,并且后台能够取到值的写法:contentEditable="false" style="color:Gray" --------
<asp:TextBox ID="txtMoney" runat="server"  CssClass="inputfiled" MaxLength="8" Width="150px" contentEditable="false" style="color:Gray" ></asp:TextBox><span>*</span>

-----------------------------按字符串实际长度截取定长字符串-CutString-----------

 <asp:TemplateField HeaderText="报警类型">
                  <ItemTemplate>
                    <asp:Label ID="DDate" runat="server"  Text='<%# CutString(Eval("AlarmName").ToString(),80)%>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>

 

 

  --------------------------------------打开Visual Studio 代码提示功能 ----------------------------------------------------
依次选 《工具》 --->《选项》 ---> 《文本编辑器》 ---> 《C#》 ---> 《常规》--->《语句结束》栏目下的《自动列出成员》《参数信息》都勾选住就可以了。

    /// <summary>
    /// 按字符串实际长度截取定长字符串
    /// </summary>
    /// <param name="str">原字符串</param>
    /// <param name="length">要截取的长度</param>
    /// <returns>string型字符串</returns>
    public static string CutString(string str, int length)
    {
        string delsqace = str.Trim();
        int i = 0, j = 0;
        foreach (char chr in delsqace)
        {
            if ((int)chr > 127)
            {
                i += 2;
            }
            else
            {
                i++;
            }
            if (i > length)
            {
                delsqace = delsqace.Substring(0, j) + "...";
                break;
            }
            j++;
        }
        return delsqace;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值