在asp.net 使用ajax 彈出的JS對話方塊

來源:互聯網
上載者:User

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ASPNETAJAXWeb.AjaxUser
{
 public class AjaxUserSystem
 {

  public AjaxUserSystem()
  {
   
  }

  /// <summary>
  /// 在ASP.NET環境中彈出一個對話方塊
  /// </summary>
  /// <param name="response"></param>
  /// <param name="message"></param>
  public static void ShowDialog(HttpResponse response,string message)
  {
   response.Write("<script>alert(\"" + message + "\");</script>");
  }

  /// <summary>
  /// 在ajax環境中彈出一個對話方塊
  /// </summary>
  /// <param name="button"></param>
  /// <param name="message"></param>
  public static void ShowAjaxDialog(Button button,string message)
  {
   ScriptManager.RegisterClientScriptBlock(button,typeof(Button),button.ClientID,message,true);
  }

  ///

  public static void ShowAjaxDialog(Page page,string message)
  {
   ScriptManager.RegisterClientScriptBlock(page,typeof(Page),DateTime.Now.ToString().Replace(":"," "),"alert('"+message"')",true);
  }

  /// <summary>
  ///  根據Value屬性把清單控制項的選擇項設定為指定項
  /// </summary>
  /// <param name="list"></param>
  /// <param name="value"></param>
  public static void ListSelectedItemByValue(ListControl list,string value)
  {
   if(list == null) return;
   ///選擇項為空白
   if(list.Items.Count <= 0)
   {
    list.SelectedIndex = -1;
    return;
   }
   ///逐項進行比較,設定選擇項
   for(int i = 0; i < list.Items.Count; i++)
   {
    if(list.Items[i].Value == value)
    {
     list.SelectedIndex = i;
     return;
    }
   }
   ///沒有合格選擇項
   list.SelectedIndex = -1;
  }

  /// <summary>
  /// 根據Text屬性把清單控制項的選擇項設定為指定項
  /// </summary>
  /// <param name="list"></param>
  /// <param name="text"></param>
  public static void ListSelectedItemByText(ListControl list,string text)
  {
   if(list == null) return;
   ///選擇項為空白
   if(list.Items.Count <= 0)
   {
    list.SelectedIndex = -1;
    return;
   }
   ///逐項進行比較,設定選擇項
   for(int i = 0; i < list.Items.Count; i++)
   {
    if(list.Items[i].Text == text)
    {
     list.SelectedIndex = i;
     return;
    }
   }
   ///沒有合格選擇項
   list.SelectedIndex = -1;
  }

  /// <summary>
  /// 根據時間建立字串
  /// </summary>
  /// <returns></returns>
  public static string CreateDateTimeString()
  {
   DateTime now = DateTime.Now;
   string dtString = now.Year.ToString()
    + now.Month.ToString().PadLeft(2,'0')
    + now.Day.ToString().PadLeft(2,'0')
    + now.Hour.ToString().PadLeft(2,'0')
    + now.Minute.ToString().PadLeft(2,'0')
    + now.Second.ToString().PadLeft(2,'0')
    + now.Millisecond.ToString().PadLeft(3,'0');
   return (dtString);
  }

 }
}

“七”樂無窮,盡在新浪新版部落格,快來體驗啊~~~請點擊進入~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.