EW Resource

Expression Web and ASP.Net

Expression Web has excellent support for ASP.Net 2/3.5/4, supporting Masterpages, database connectivity etc, with a toolbox containing the asp.net controls that can be dragged onto you page. This can produce pages with complex functionality very quickly.

However, it relies solely on the built-in configurations that the controls use, (which are very powerful) and does not encourage you, or offer you the tools to add additional code. This has to be done by hand and whilst this is very possible, for serious ASP.Net development you need to use Expression Web alongside MS Visual Studio 2005 or Visual Web Developer Express.

Despite this it is perfectly possible to add additional code to you pages and enhance the results displayed.


Lets look at some simple hand coding that you might want to add to an aspx page.

(Examples given in VB)

First, to add code to you page you need to add a script block, either inside the <head> tags of your page, or, if you're using a masterpage, within the head ContentPlaceHolder.

<script type="text/vb" runat="server">

</script>

Here's a simple function that checks whether a field read from a database table has a value and displays the result accordingly, placed with this script block.

<script type="text/vb" runat="server">

Function DetailStr(ByVal detail) As String

If detail.ToString <> "" Then

DetailStr = "<b>Details</b><br/>" & detail

Else

DetailStr = "There are no details for this entry"

End If

End Function

</script>

(You'll notice that Expression Web gives you no intellisense when you type the code in, which VS would).


Next, let create a function to do something when a button is clicked.

First, add the OnClick event to the button: note that the ID of the button is 'myBtn'

<asp:Button ID="myBtn" runat="server" Text="Button" OnClick="myBtn_Click" />

The add the function into the script block:

<script runat="server">

Protected Sub myBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

'we still need to create our action here

End Sub

</script>


Finally, you might want to check whether a page has been loaded via the SSL certificate it's configured to use. For this we use a Page Load subroutine.

<script type="vb/text" runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

If Request.ServerVariables("SERVER_PORT") <> 443 Then

Response.Redirect("https://www.xxx.com/default.aspx")

End If

End Sub

</script>