Microsoft Technology, .Net, BizTalk, Sharepoint & etc.

Liedong(Ken) Zheng, Senior SharePoint Developer at SIMPLOT

Archive for June, 2008

CheckBox and CheckBoxList Validators for multiple checkboxlists

Posted by ken zheng on June 27, 2008

Use 4Guys Creating CheckBox and CheckBoxList Validators in ASP.NET 2.0, you can build a custom validator control for your Checkbox and checkboxlist. But if you have more than one CheckBoxList in your page, the validator will not work because the Javascript will only apply to one control.

What you can do is modify the validator class to create an individual javascript for each validator.

In GenerateClientValidation method

change to:

….

Attributes["evaluationfunction"] = "VerifyItemSelected_" + <strong>ControlToValidate</strong>;

StringBuilder scriptBuilder = new StringBuilder();

scriptBuilder.Append(@"&lt;script language='javascript'&gt;");
scriptBuilder.Append(string.Format("function VerifyItemSelected_{0}", <strong>ControlToValidate</strong>));
scriptBuilder.Append(@"() {");
scriptBuilder.Append(string.Format("var targetControlName = document.getElementById('{0}')", this.ClientID));
scriptBuilder.Append(@".controltovalidate;");

…..

Finally,

Page.ClientScript.RegisterClientScriptBlock(typeof(CheckBoxListValidator), “CustomCheckboxListValidationScript_” + ControlToValidate, scriptBuilder.ToString());

By changing the code, we can ensure all the validator scripts are being registered.

Posted in .Net, VS2008 | Tagged: , | 1 Comment »

CSS Inheritance

Posted by ken zheng on June 26, 2008

we can assign multiple class names to a single element? That means we can change the style sheet so it looks like this:

.boxOut {
  width: 12em;
  padding: 0.5em;
  margin: 0.5em;
  border: solid 1px black;
}

.oddBoxOut {
  float: left;
}

.evenBoxOut {
  float: right;
}

And then the HTML will look like:

<div class="boxOut oddBoxOut">

Grouping Selectors

A single style may have multiple selectors assigned to it through the use of grouping.

To revisit the previous example, we first simplify the HTML so we only mention the one class:

<div class="oddBoxOut">

Then we assign the CSS we want to it, but we group the common property/value pairs.

.oddBoxOut,
.evenBoxOut {
  width: 12em;
  padding: 0.5em;
  margin: 0.5em;
  border: solid 1px black;
}

.oddBoxOut {
  float: left;
}

.evenBoxOut {
  float: right;
}

These two techniques should solve most problems which people think can be solved with OO-style inheritance

Posted in .Net | Tagged: | Leave a Comment »

ListView ItemTemplate and AlternatingItemTemplate

Posted by ken zheng on June 25, 2008

The ASP.NET 3.5 ListView server control provides an ItemTemplate and an AlternatingItemTemplate.  Only the ItemTemplate is required for defining each row’s content.  The AlternatingItemTemplate can be used to define row content for odd numbered rows, however quite often the even and odd rows are identical with the exception that a different CSS class definition needs to be used, so to provide a different visible experience to the user.  Rather than duplicate the bulk of the ItemTemplate into the AlternatingItemTemplate, one can provide inline code to examine the container’s row number and return a specific even or odd CSS class name, illustrated as follows:

   1:  <asp:ListView ID="listViewSort"
   2:      DataSourceID="ObjMenu"
   3:      DataKeyNames="Name"
   4:      runat="server">
   5:      <LayoutTemplate>
   6:          <table runat="server"
   7:              class="listViewGrid"
   8:              cellspacing="0"
   9:              border="0">
  10:  
  11:              <tr runat="server" id="itemPlaceholder" />
  12:  
  13:          </table>
  14:      </LayoutTemplate>
  15:      <ItemTemplate>
  16:          <tr class="<%# ((ListViewDataItem)Container).DisplayIndex % 2 == 0 ? "itemRow" : "altItemRow" %>">
  17:              <td align="left" style="width: 200px;">
  18:                  <asp:Label runat="server"
  19:                      Text=’<%# Eval("Name") %>’ />
  20:              </td>
  21:              <td align="right" style="width: 100px;">
  22:                  <asp:Label runat="server"
  23:                      Text=’<%# Eval("Price") %>’ />
  24:              </td>
  25:              <td align="left" style="width: 400px;">
  26:                  <asp:Label runat="server"
  27:                      Text=’<%# Eval("Description") %>’ />
  28:              </td>
  29:              <td align="right" style="width: 100px;">
  30:                  <asp:Label runat="server"
  31:                      Text=’<%# Eval("Calories") %>’ />
  32:              </td>
  33:          </tr>
  34:      </ItemTemplate>
  35:  </asp:ListView>

 

 

If the inline processing is more complicated than one would prefer for inline code, then one can invoke a protected web page method to accomplish similar or more complicated tasks, illustrated as follows:

   1:  <asp:ListView ID="listViewSort"
   2:      DataSourceID="ObjMenu"
   3:      DataKeyNames="Name"
   4:      runat="server">
   5:      <LayoutTemplate>
   6:          <table runat="server"
   7:              class="listViewGrid"
   8:              cellspacing="0"
   9:              border="0">
  10:  
  11:              <tr runat="server" id="itemPlaceholder" />
  12:  
  13:          </table>
  14:      </LayoutTemplate>
  15:      <ItemTemplate>
  16:          <tr class="<%# GetCssName(Container) %>">
  17:              <td align="left" style="width: 200px;">
  18:                  <asp:Label runat="server"
  19:                      Text=’<%# Eval("Name") %>’ />
  20:              </td>
  21:              <td align="right" style="width: 100px;">
  22:                  <asp:Label runat="server"
  23:                      Text=’<%# Eval("Price") %>’ />
  24:              </td>
  25:              <td align="left" style="width: 400px;">
  26:                  <asp:Label runat="server"
  27:                      Text=’<%# Eval("Description") %>’ />
  28:              </td>
  29:              <td align="right" style="width: 100px;">
  30:                  <asp:Label runat="server"
  31:                      Text=’<%# Eval("Calories") %>’ />
  32:              </td>
  33:          </tr>
  34:      </ItemTemplate>
  35:  </asp:ListView>

 

The protected web page method in turn can provide simple or more complex logic.  In this illustration, the same logic is provided as the inline code example:

   1:  protected string GetCssName(object container)
   2:  {
   3:      if (container != null)
   4:      {
   5:          if (container.GetType() == typeof(ListViewDataItem))
   6:          {
   7:              if ((((ListViewDataItem)container).DisplayIndex % 2) == 0)
   8:              {
   9:                  return "itemRow";
  10:              }
  11:              else
  12:              {
  13:                  return "altItemRow";
  14:              }
  15:          }
  16:      }
  17:      return null;
  18:  }

 

 

While the ListView server control AlternatingItemTemplate is quite useful, its use should be limited to instances where there is truly differing content requirements between even and odd numbered rows.  The above illustrations also works equally as well with my previously posted ListViewSort custom control.

Posted in .Net, VS2008 | Tagged: | 1 Comment »

CSS Stylizer

Posted by ken zheng on June 25, 2008

Been playing with this http://www.skybound.ca/stylizer/ CSS editor lately, and it has some really nice features:

It has a drop down to indicate only certain style elements appear in certain browser flavours:

That’s pretty cool. I just use a bookmark for that at the moment (http://www.noupe.com/better-design/7-css-hacks-you-cannt-live-without.html) but IDE integration would rock.

Posted in Uncategorized | Tagged: | 1 Comment »

SharePointDeveloper

Posted by ken zheng on June 23, 2008

New Sharepoint development resource site

http://www.microsoft.com/click/SharePointDeveloper/

Posted in Sharepoint | Tagged: | Leave a Comment »

Configuring CRM wrt application integration

Posted by ken zheng on June 22, 2008

Configuring CRM wrt application integration is a nightmare, but you can find some useful tools to work with.

Here’s a set of sample data:

http://www.microsoft.com/downloads/details.aspx?FamilyId=D5F77EE7-3D01-4944-B5DC-C8CDC8123DF4&displaylang=en

And there’s also a tool for generating test data, and lets you save your data out of CRM back into an xml packet for later reuse:

(crm demonstration tools:)

http://www.microsoft.com/downloads/details.aspx?familyid=634508DC-1762-40D6-B745-B3BDE05D7012&displaylang=en

Posted in CRM | Leave a Comment »

CRM 4 unauthorized web access

Posted by ken zheng on June 20, 2008

calls CRM’s web services  we always get error “The request failed with HTTP status 401: Unauthorized.”

The reason is CRM 4.0 was being used, and multi-instancing is a problem. You need to provide an auth token that specifies by customer name which instance you intend to use.

http://msdn.microsoft.com/en-us/library/cc151052.aspx

Posted in CRM | Tagged: | Leave a Comment »

Wireless Networking: Windows Vista VPN Setup

Posted by ken zheng on June 18, 2008

hese instructions explain how to set up a Virtual Private Network (VPN) in Windows Vista.

Click on the Start icon and select Control Panel

Click Network and Internet and select Network and Sharing Center

From within Network and Sharing Center select Set up a connection or network on the left side of the screen

Scroll down and select Connect to a workplace and click Next

Select Use my Internet connection (VPN)

Select I’ll set up an Internet connection later

Enter vpn.glos.local in the Internet address: box and click Next

Enter your University username and password and click Create

The screen below should then appear.  Click Close

In this Section…

Wireless

Wireless Networking – Windows Vista Setup

Wireless Networking – Windows Vista VPN Setup

Wireless Networking – Connecting with Windows Vista

Wireless Networking – XP Setup

Wireless Networking – VPN Setup

Wireless FAQ’s

Posted in Handy Tips | 1 Comment »

Use LET keyword in LINQ

Posted by ken zheng on June 13, 2008

As Luke Hoban explains on his blog:

With let query clauses, you can introduce a variable into scope and use it in the subsequent query clauses. Similar to local variables in a method body, this gives you a way to avoid evaluating a common expression multiple times by storing it in a variable. This can be very useful even in much simpler queries. Of course, in the query above – let is absolutely critical.

The “query above” he refers to is a ray tracer coded as a big LINQ query full of let clauses!

Let’s see is an example from the official LINQ forum.
Someone asked how to query the following XML document:

<cars>
<car name="Toyota Coupe">
<profile name="Vendor" value="Toyota"/>
<profile name="Model" value="Celica"/>
<profile name="Doors" value="2"/>
<support name="Racing" value="yes"/>
<support name="Towing" value="no"/>
</car>
<car name="Honda Accord Aerodec">
<profile name="Vendor" value="Honda"/>
<profile name="Model" value="Accord"/>
<profile name="Doors" value="4"/>
<support name="Racing" value="no"/>
<support name="Towing" value="yes"/>
</car>
</cars>

Here is one way to do it:

from car in root.Elements("car")
let profiles =
from profile in car.Elements("profile")
select new {
Name = profile.Attribute("name").Value,
Value = profile.Attribute("value").Value
}
let supports =
from support in car.Elements("support")
select new {
Name = support.Attribute("name").Value,
Value = support.Attribute("value").Value
}
select new Car {
Name = car.Attribute("name").Value,
Vendor = profiles.Single(prof => prof.Name == "Vendor").Value,
Model = profiles.Single(prof => prof.Name == "Model").Value,
Doors = int.Parse(profiles.Single(prof => prof.Name == "Doors").Value),
RacingSupport = supports.Single(sup => sup.Name == "Racing").Value == "yes"
};


It’s easier to isolate the “profile” and “support” elements in separate sequences using let clauses, as above. Then the select clause becomes simple to write.

Posted in LINQ | Tagged: , | Leave a Comment »

Silverlight 2 Beta2 Released

Posted by ken zheng on June 9, 2008

Silverlight 2 Beta2 was released today.  You can download both Silverlight 2 Beta2 and the Visual Studio and Expression Blend tools support to target it here.

Beta2 adds a lot of new features (more details below), but is still a 4.6 MB download that takes less than 10 seconds to install on a machine.  It does not require the .NET Framework or any other software to be installed for it to work, and all features work cross-browser on both Mac and Windows machines.  These features will also be supported on Linux via the Moonlight 2 release.

Silverlight 2 Beta2 supports a go-live license that allows you to start using and deploying Silverlight 2 for commercial applications. There will be some API changes between Beta2 and the final release, so you should expect that applications you write with Beta2 will need to make some updates when the final release comes out.  But we think that these changes will be straight-forward and relatively easy, and that you can begin planning and starting commercial projects now.

You can build Silverlight Beta2 applications using the VS 2008 Tools for Silverlight and Expression Blend 2.5 June Preview downloads.  You can download both of them here.  The VS 2008 Tools for Silverlight download works with both VS 2008 and the recent VS 2008 SP1 beta release.

Posted in Uncategorized | Tagged: | Leave a Comment »