Friday, June 17, 2011

Inline ASP.NET Tags

<% ... %>
<% if (User.IsInRole("admin")) { %>
You can see this
<% } else { %>
You are no admin fool!
<%} %>
http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx



<%= ... %>
Used for small chunks of information, usually from objects and single pieces of information like a single string or int variable:

The Date is now <%= DateTime.Now.ToShortDateString() %>
The value of string1 is <%= string1 %>
http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx
*note: <%= is the equivalent of Response.Write()
<%# .. %> Used for Binding Expressions; such as Eval and Bind, most often found in data controls like GridView, Repeater, etc.:



<%# Eval("MeetingName") %>
http://msdn2.microsoft.com/en-us/library/ms178366.aspx



<%$ ... %>
Used for expressions, not code; often seen with DataSources:
http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx



<%@ ... %>
This is for directive syntax; basically the stuff you see at the top your your aspx pages like control registration and page declaration:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<%@ Register TagPrefix="wp" Namespace="CustomWebParts" %>
http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx



<%-- ... --%>
This is a server side comment, stuff you don't want anyone without code access to see:
<%-- sometimes end users make me angry --%>
http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx

Sunday, May 1, 2011

I found the following solution from http://forums.asp.net/t/1114630.aspx/1/10 . It saved me many hours of trial and error ahead of time. Using the following config change, you can easily change the connectionString used by datasets in the XSD file to another connectionString in one place.

<configuration>
<connectionStrings>
<add name="PROJECT_NAMESPACE.Properties.Settings.YOURCONNECTIONSTRING"
connectionString="Data Source=YOURSQLSERVER;Initial Catalog=YOURDATABASE;
Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

  1. Create your App.Config file

  2. The above XML is all you need in there

  3. Swap out the "PROJECT_NAMESPACE" with your project or assemblies default namespace and "YOURCONNECTIONSTRING" with the Settings.settings file entry, be sure that settings entry is of type "(Connection String)"

  4. Copy the <add /> node from app.config / connectionStrings for this setting into your Web.Config, and that's it, now you can simply configure the connection using the web.config, and retain the original designer connection without ever having to alter the XSD.