Jquery和Asp.net2.0結合的小技巧。

來源:互聯網
上載者:User
關鍵詞:Jquery,asp.net 2.0 ,資料控制項
主要功能,簡化代碼,實現在刪除功能之前彈出對話方塊提示。

asp.net2.0資料控制項中,很多都有刪除功能的, 通常我們在刪除操作之前都會提示使用者。按照以前的方式,我們是在控制項LinkButton 之前寫上自訂的屬性OnClick,現在有了jQuery,我可以這樣實現。代碼只支援LinkButton刪除方式,還不支援Button! /**//// <summary>
    ///  操作時彈出對話方塊,需要Jquery支援
    /// </summary>
    /// <param name="message"></param>
    /// <param name="hreftext"></param>
    public static void ConfirmCommandMessageUseJquery(Page page,string message, string commandType)
    {
        string js = "$(document).ready(function(){  var arr = $(\"a\"); arr.each(function(){ var s = this.href; if(s.indexOf(\"" + commandType + "\")!=-1)  {  $(this).click(function(){ return confirm('" + message + "'); });} });  });";

        ClientScriptManager cs = page.ClientScript;
        if (!cs.IsStartupScriptRegistered("jqueryDelete"))
        {
            cs.RegisterStartupScript(typeof(Page), "jqueryDelete", js, true);
        }
    }

 protected void Page_Load(object sender, EventArgs e)
    {
        ClientScriptManager cs = Page.ClientScript;
        if (!cs.IsClientScriptIncludeRegistered(typeof(Page), "jquery")) //註冊jquery
        {
            cs.RegisterClientScriptInclude(typeof(Page), "jquery", ResolveUrl("~/js/jquery.js"));
        }
    }

頁面調用 JScript.ConfirmCommandMessageUseJquery(this, "確定刪除使用者,刪除使用者會刪除使用者其他相關的記錄,請小心操作!", "Delete");

關於Jquery的使用,請瀏覽官方網站
www.jquery.com

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.