可以在每個ASP.NET控制項的Smart Tasks中自動加入一個[Edit Expression]按鈕
按下後就能開啟VS內建的Expression編輯視窗來編輯各種運算式的內容

這是Visual Studio的外掛功能,需要安裝請到這裡下載ASP.NET Excalibur Package
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>MVVM By Auto ViewModel Base</title>
</head>
<body>
<form id="form1" runat="server">
<div>
請輸入您的大名:<asp:TextBox ID="TextBox1" runat="server" Text="<%$ Binding: Name %>"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="確定" OnClick="<%$ Binding: Button1_Click %>" /><br />
<br />
<asp:Label ID="Label1" runat="server" Text="<%$ Binding: Text %>"></asp:Label>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ViewModel_Hello3 : ViewModel.Base.Default3
{
protected void Page_Load(object sender, EventArgs e)
{
}
public override void Button1_Click(object sender, EventArgs e)
{
if (Name != "")
{
Text = Name + ",您好。";
}
else
{
Text = "請輸入名字";
}
base.Button1_Click(sender, e);
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Register Src="ViewModel/Hello3.ascx" TagName="Hello3" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>MVVM By Auto ViewModel Base</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:Hello3 ID="ViewModel" runat="server" />
請輸入您的大名:<asp:TextBox ID="TextBox1" runat="server" Text="<%$ Binding: Name %>"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="確定" OnClick="<%$ Binding: Button1_Click %>" /><br />
<br />
<asp:Label ID="Label1" runat="server" Text="<%$ Binding: Text %>"></asp:Label>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Register Src="UserControl.ascx" TagName="UserControl" TagPrefix="uc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Bind Control & Method</title> </head> <body> <form id="form1" runat="server"> <div> <uc1:UserControl ID="UserControl1" runat="server" /> <asp:Label ID="Label1" runat="server" Text='<%$ Binding : ID = UserControl1, GetText %>'></asp:Label> <asp:Panel ID="Panel1" runat="server" ToolTip="456"> <asp:Label ID="Label2" runat="server" Text='<%$ Binding : Type = Panel, ToolTip %>'></asp:Label> </asp:Panel> <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" Text="789"></asp:TextBox> <asp:Label ID="Label3" runat="server" Text='<%$ Binding : ID = TextBox1, Mode = OneWay , Text %>'></asp:Label> <%-- Mode => Default, OneWay, TwoWay --%> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class UserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } public string GetText() { return "123"; } }