Ext.net中的MessageBox的簡單應用實現代碼_實用技巧

來源:互聯網
上載者:User
地址:http://examples.ext.net/
執行個體中,使用的方法貌似挺複雜的。
前台.aspx檔案中
複製代碼 代碼如下:

<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
[DirectMethod]
public void DoConfirm()
{
X.Msg.Confirm("Message", "Confirm?", new MessageBoxButtonsConfig
{
Yes = new MessageBoxButtonConfig
{
Handler = "CompanyX.DoYes()",
Text = "Yes Please"
},
No = new MessageBoxButtonConfig
{
Handler = "CompanyX.DoNo()",
Text = "No Thanks"
}
}).Show();
}
[DirectMethod]
public void DoYes()
{
this.Label1.Text = "YES";
}
[DirectMethod]
public void DoNo()
{
this.Label1.Text = "NO";
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Confirm MessageBox with ButtonsConfig - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" type="text/css" />
</head>
<body>
<ext:ResourceManager runat="server" DirectMethodNamespace="CompanyX" />
<form runat="server">
<p>
<ext:Button runat="server" Text="Confirm" Icon="Error">
<Listeners>
<Click Handler="CompanyX.DoConfirm()" />
</Listeners>
</ext:Button>
</p>
</form>
</body>
</html>

分別寫兩個函數,判斷執行那個。每個函數都要在前面標記【DirectMethod】。感覺好複雜。後來找了下按鈕的事件,發現了個簡單的方法。
.aspx檔案body中的代碼如下:
複製代碼 代碼如下:

<body>
<ext:ResourceManager runat="server" DirectMethodNamespace="CompanyX" />
<form runat="server">
<p>
<ext:Button runat="server" Text="Confirm" Icon="Error">
<DirectEvents>
<Click OnEvent="Confirm">
<Confirmation ConfirmRequest="true" Title="提示" Message="您確定要刪除嗎?" />
</Click>
</DirectEvents>
</ext:Button>
</p>
</form>
</body>

其實,可以直接在按鈕中寫,作用是在執行後台Confirm事件的時候,先彈出MessageBox框,上面兩個按鈕,確定和取消。如果選確定,才執行後台事件,否則就不會跳轉到後台。這個方法很好的解決了簡單的提示框功能。
背景Confirm事件代碼:
複製代碼 代碼如下:

protected void Confirm(object sender, DirectEventArgs e)
{
X.Msg.Alert("點擊提示", "您點擊了確定,執行的是後台事件!").Show();
}

大家可以借鑒,歡迎大家一起交流。

聯繫我們

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