Selected Category: ASP.NET (7)

View Mode: Post List Post Summary

ASP.NET MVC 2 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern. The framework encourages developers to maintain a clear separation of concerns among the responsibilities of the application – the UI logic using the view, user-input handling using the controller, and the domain logic using the model. ASP.NET MVC applications are easily testable using techniques such as test-driven development (TDD).


The installation package includes templates and tools for Visual Studio 2008 SP 1 to increase productivity when writing ASP.NET MVC applications. For example, the Add View dialog box takes advantage of customizable code generation (T4) templates to generate a view based on a model object. The default project template allows the developer to automatically hook up a unit-test project that is associated with the ASP.NET MVC application.

Because the ASP.NET MVC framework is built on ASP.NET 3.5 SP 1, developers can take advantage of existing ASP.NET features like authentication and authorization, profile settings, localization, and so on.

 

Download:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=3b537c55-0948-4e6a-bf8c-aa1a78878da0

Posted by anISV at 痞客邦 PIXNET Comments(1) Trackback(0) Hits(18)

 

Problem:

之前在專案中, 有測到一個疑似一個 .NET Framework Regex 的 bug?

例如使用 PATTERN = “\w”

\w表示任何一個字元與數字以及 '_' ,意同 [a-zA-Z0-9_]

輸入全形英數字及中文字可以通過在 Server side 的 Regular expression 檢查

但相同的 pattern 在 Javascript 的 Regular expression 是不會過的

最近找到答案了…

Root Cause:

    Server side RegExp uses a different regular expression engine than JavaScript.

Solution:

    You can get compatible behavior by using a RegexOptions.EcmaScript with your Regex.

    Regex regexp = new Regex("\\w", RegexOptions.ECMAScript);

    For more information:

    RegexOptions 列舉型別

    http://msdn.microsoft.com/zh-tw/library/system.text.regularexpressions.regexoptions.aspx

    ECMAScript vs. Canonical Matching Behavior

    http://msdn.microsoft.com/en-us/library/04ses44d(VS.71).aspx

Sample:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RegExpApp._Default" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>

<!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>Untitled Page</title>
<script language="javascript" type="text/javascript">
function testRegExp()
{
var email = document.getElementById("<%=txtEmail.ClientID %>").value;
var regexp = new RegExp("\\w");
if (email.match(regexp)) {
alert("Successful match");
} else {
alert("No match");
}
}
</script>


<script runat="server">
protected void btnNETRegExp_Click(object sender, EventArgs e)
{
Regex regexp;

if (chkECMAScript.Checked)
{
regexp = new Regex("\\w", RegexOptions.ECMAScript);
}
else
{
regexp = new Regex("\\w");
}

if(regexp.IsMatch(txtEmail.Text))
{
Response.Write("Successful match");
}
else{
Response.Write("No match");
}

}


</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnNETRegExp" runat="server" Text="NET RegExp" OnClick="btnNETRegExp_Click" />
&nbsp;&nbsp;&nbsp;
<asp:CheckBox ID="chkECMAScript" runat="server" />
<br />
<br />
<input id="btnJSRegExp" type="button" value="JavaScript RegExp" onclick="testRegExp();" /></div>
</form>
</body>
</html>

 

Hope this helps.

Posted by anISV at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(58)

 

這也是在專案上遇到的一個問題,目前可以對 DropDownList 控制項設定 Tooltip,但無法直接從 VS 的 IDE 屬性頁直接設定。

所以筆者用以下程式碼來對每一個項目加入 Tooltip:

 

for (int i = 0; i < yourDropDownList.Items.Count; i++)
{
   yourDropDownList.Items[i].Attributes.Add("title", yourDropDownList.Items[i].Text);
}

 


其效果就是滑鼠移到每一個項目上時,即會出現 Tooltip 的說明。


 


Enjoy.

Posted by anISV at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(48)

前一陣子在專案中,為了讓使用者可以更清楚的知道自己所選取的項目為何,所以筆者必須將 RadioButtonList 中被選取的選項加上粗體的樣式。
本想應該是很簡單,只要把 RadioButtonList 中的項樣的樣式設定即可,但是
竟發現 RadioButtonList 並未提供針對其每個選項設定樣式的功能。XD…
也可以從產生出來的網頁的原始碼發現 RadioButtonList 產生的程式碼為 <label for=”……”>XXX</label> 的寫法。如下:
 
<table id="RadioButtonList1" border="0">
	<tr>
	  <td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="選項一" /><label for="RadioButtonList1_0">選項一</label></td>
	</tr>
        <tr>
	  <td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="選項二" /><label for="RadioButtonList1_1">選項二</label></td>
	</tr>
        <tr>
	  <td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="選項三" /><label for="RadioButtonList1_2">選項三</label></td>
	</tr>
</table>

 


試了一些方法後,最後筆者用一個 div 將 RadioButtonList 放在其中,再用 JavaScript 來描這個 div 中的 label 的 Tag


程式碼如下:


 

    function MakeBold(divObj, elementID) {
        var labels = divObj.getElementsByTagName("label");
        for(var i=0;i<labels.length;i++) 
        {
            if(labels.item(i).htmlFor == elementID) 
            {
                labels.item(i).style.fontWeight="bold";
            }
            else
            {
                labels.item(i).style.fontWeight="normal";
            }
        }
    }

 


P.S. 請記得在每個選項加入 onclick 的事件來觸發它。


Hope this helps.

Posted by anISV at 痞客邦 PIXNET Comments(1) Trackback(0) Hits(64)

ASP.NET MVC 1.0 provides a new Model-View-Controller (MVC) framework on top of the existing ASP.NET 3.5 runtime. This means that developers can take advantage of the MVC design patterns to create their Web Applications which includes the ability to achieve and maintain a clear separation of concerns (the UI or view from the business and application logic and backend data), as well as facilitate test driven development (TDD). The ASP.NET MVC framework defines a specific pattern to the Web Application folder structure and provides a controller base-class to handle and process requests for “actions”. Developers can take advantage of the specific Visual Studio 2008 MVC templates within this release to create their Web applications, which includes the ability to select a specific Unit Test structure to accompany their Web Application development.

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b

Posted by anISV at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(63)

The ASP.NET MVC RC2 release provides a new Model-View-Controller (MVC) framework on top of the existing ASP.NET 3.5 runtime. This means that developers can take advantage of the MVC design patterns to create their Web Applications which includes the ability to achieve and maintain a clear separation of concerns (the UI or view from the business and application logic and backend data), as well as facilitate test driven development (TDD). The ASP.NET MVC framework defines a specific pattern to the Web Application folder structure and provides a controller base-class to handle and process requests for “actions”. Developers can take advantage of the specific Visual Studio 2008 MVC templates within this release to create their Web applications, which includes the ability to select a specific Unit Test structure to accompany their Web Application development.

下載位置:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ee4b2e97-8a72-449a-82d2-2f720d421031

 

Enjoy.

Posted by anISV at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(30)

The ASP.NET MVC RC1 release provides a new Model-View-Controller (MVC) framework on top of the existing ASP.NET 3.5 runtime. This means that developers can take advantage of the MVC design patterns to create their Web Applications which includes the ability to achieve and maintain a clear separation of concerns (the UI or view from the business and application logic and backend data), as well as facilitate test driven development (TDD). The ASP.NET MVC framework defines a specific pattern to the Web Application folder structure and provides a controller base-class to handle and process requests for “actions”. Developers can take advantage of the specific Visual Studio 2008 MVC templates within this release to create their Web applications, which includes the ability to select a specific Unit Test structure to accompany their Web Application development.

 

The MVC framework is fully extensible at all points, allowing developers to create sophisticated structures that meet their needs, including for example Dependency Injection (DI) techniques, new view rendering engines or specialized controllers.

 

As the ASP.NET MVC framework is built on ASP.NET 3.5, developers can take advantage of many existing ASP.NET 3.5 features, such as localization, authorization, Profile etc.

 

Note: A couple of issues have been reported with the RC. We will post a refresh on Friday, January 30, 2009

 

下載位置:http://www.microsoft.com/downloads/details.aspx?FamilyID=f4e4ee26-4bc5-41ed-80c9-261336b2a5b6&DisplayLang=en#filelist

 

Enjoy.

Posted by anISV at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(44)