Posted on 7/21/2011

In order to use the browser scroll bars, edit the html page that is hosting the SL control. The Silverlight object tag is set to 100% height/width by default, and the div/body tags are set to 100% height as well.

Set the height and width of the Silverlight object to match your explicit sizes in your mainpage.xaml and you should see the browser scrollbars. Of course, only when the Silverlight page’s height and width exceeds the browsers.


    <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="775" height="650">
          <param name="source" value="ClientBin/MyApplication.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="4.0.50826.0" />
          <param name="autoUpgrade" value="true" />
          <a href="" style="text-decoration:none">
               <img src="" alt="Get Microsoft Silverlight" style="border-style:none"/>
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
Posted on 7/20/2011

Assembly caching provides a mechanism to avoid packaging common DLLs into the application’s .xap file. This will reduce the application’s load time and make subsequent upgrades to the application easier.

Using assembly caching can be activated by selecting “Reduce XAP size by using application library caching” under the Silverlight project’s property pages Silverlight tab.


Note: Assembly caching is only available for browser-hosted applications and not for out-of-browser applications. That may change in future editions.

Posted on 7/12/2011

Creating the Membership Database.

Locate and run aspnet_reqsql.exe from a DOS prompt.  It should be located in  c:\Windows\Microsoft.NET\Framework\v4.030319.

The ASP.NET SQL Server Setup Wizard creates the Web site in the instance you specify in the wizard. The key is to modify the Web.config in your project to access the local aspnetdb.mdf.

      <add name="LocalSqlServer"
         connectionString="data source=(local); Integrated Security=SSPI;Initial Catalog=aspnetdb;"
         providerName="System.Data.SqlClient" />


or , if you are using SQL Server from the Internet you would use a connection string like below.

    <add name="MembershipConnectionString"
         connectionString="Data; InitialCatalog=SQL2005_77; Persist Security Info=True;User ID=SQL2005_77_user; Password=password"
         providerName="System.Data.SqlClient" />
Posted on 7/12/2011

Storing phone numbers in a table without the dashes and parenthesis sounds like a good idea, until you need to retrieve and format them correctly. As always, reading the documentation - and understanding it - can be time consuming and frustrating. Which it was! But this is what I finally came up with...

This will return (123) 456-7890

public partial class Report1 : Telerik.Reporting.Report
        public Report1()

        public static string FormatPhoneNumber(string phoneNumber)
            if (phoneNumber.Length == 10)
                return "(" + phoneNumber.Substring(0, 3) + ") " + 
                      phoneNumber.Substring(3, 3) + "-" +
                return "no phone number";

Then in the "Value" property of the text box use the following: =FormatPhoneNumber(Fields.Phone)

Of course, you can modify this and take into consideration that the phone number may not have an area code. But who doesn't use area codes?

Posted on 7/6/2011

Here is a quick way to load the states into a RadComboBox.

Cut and paste the ComboBox.xml into an separate .xml file. Then place BindComboBox() into the code-behind of the .aspx file and call it from Page_Load().

The values in the list can be modified, but it should save time instead of creating it from scratch

private void BindStateCombo()
            // load State combo box
            string path = "combobox.xml";
            StreamReader sr = method(path);

private StreamReader method(string path)
            StreamReader sr = new StreamReader(Server.MapPath(path));
            return sr;

protected void Page_Load(object sender, EventArgs e)
            if (!Request.IsAuthenticated) { Response.Redirect("Login.aspx"); }

              // load combo boxe




<?xml version="1.0" encoding="utf-8" ?>
<Item Text="States" IsSeparator="true" />
<Item  Value="AL" Text="Alabama" />
<Item  Value="AK" Text="Alaska" />
<Item  Value="AZ" Text="Arizona" />
<Item  Value="AR" Text="Arkansas"  />
<Item  Value="CA" Text="California"  />
<Item  Value="CO" Text="Colorado" />
<Item  Value="CT" Text="Connecticut" />
<Item  Value="DC" Text="District of Columbia" />
<Item  Value="DE" Text="Delaware" />
<Item  Value="FL" Text="Florida" />
<Item  Value="GA" Text="Georgia" />
<Item  Value="HI" Text="Hawaii" />
<Item  Value="ID" Text="Idaho" />
<Item  Value="IL" Text="Illinois" />
<Item  Value="IN" Text="Indiana" />
<Item  Value="IA" Text="Iowa" />
<Item  Value="KS" Text="Kansas" />
<Item  Value="KY" Text="Kentucky" />
<Item  Value="LA" Text="Louisiana" />
<Item  Value="ME" Text="Maine"  />
<Item  Value="MD" Text="Maryland" />
<Item  Value="MA" Text="Massachusetts" />
<Item  Value="MI" Text="Michigan" />
<Item  Value="MN" Text="Minnesota" />
<Item  Value="MS" Text="Mississippi" />
<Item  Value="MO" Text="Missouri" />
<Item  Value="MT" Text="Montana" />
<Item  Value="NE" Text="Nebraska" />
<Item  Value="NV" Text="Nevada" />
<Item  Value="NH" Text="New Hampshire" />
<Item  Value="NJ" Text="New Jersey" />
<Item  Value="NM" Text="New Mexico" />
<Item  Value="NY" Text="New York" />
<Item  Value="NC" Text="North Carolina" />
<Item  Value="ND" Text="North Dakota" />
<Item  Value="OH" Text="Ohio" />
<Item  Value="OK" Text="Oklahoma" />
<Item  Value="OR" Text="Oregon" />
<Item  Value="PA" Text="Pennsylvania" />
<Item  Value="RI" Text="Rhode Island"  />
<Item  Value="SC" Text="South Carolina"  />
<Item  Value="SD" Text="South Dakota" />
<Item  Value="TN" Text="Tennessee" />
<Item  Value="TX" Text="Texas" />
<Item  Value="UT" Text="Utah" />
<Item  Value="VT" Text="Vermont" />
<Item  Value="VA" Text="Virginia" Selected="True" />
<Item  Value="WA" Text="Washington" />
<Item  Value="WV" Text="West Virginia" />
<Item  Value="WI" Text="Wisconsin" />
<Item  Value="WY" Text="Wyoming" />


Download:  combobox.xml (2.09 kb)

Posted on 7/5/2011

Sending an email from a web page using the Silverlight-enabled WCF Service.


First, using Visual Studio 2010, create a new Silverlight Application project and use ContactEmail as the project’s name.


When this dialog appears, make sure the checkbox for “Host the Silverlight application in a new Web Site” is checked.




Visual Studio will open the MainPage.xaml file in the IDE.


Change the MainPage.xaml file to match the one below.

<UserControl x:Class="ContactEmail.MainPage"
    d:DesignHeight="400" d:DesignWidth="600">
    <Grid x:Name="LayoutRoot" Margin="10">
        <StackPanel x:Name="EmailPanel" Width="293" Canvas.Left="529" Canvas.Top="99" Margin="134,0,135,0">
            <TextBlock x:Name="name" HorizontalAlignment="Left" Text="Name:" />
            <TextBox Name="txtName"   />
            <TextBlock x:Name="phone" HorizontalAlignment="Left" Text="Phone:" />
            <TextBox Name="txtPhone"   />
            <TextBlock x:Name="txtemail" HorizontalAlignment="Left" Text="Email:" />
            <TextBox Name=”txtEmail” TextWrapping="Wrap"/>
            <TextBlock x:Name="txtComment" HorizontalAlignment="Left" Text="Comments:" TextWrapping="Wrap" />
            <RichTextBox  Name="txtComments"  Height="95"/>                      
            <Button Height="33" x:Name="btnSumit"   Content="Submit" Width="80" />

Click the Design Tab  - bottom of page – to view the MainPage.xaml. The page should look like the one below. Save the MainPage.xaml.




Add a new item to the ContactEmail.Web project.


In the Installed Templates – left panel – select Silverlight. From the center panel, select Silverlight-enabled WCF Service. Use EmailService.svc for the name of the service.


Visual Studio will add the necessary files to the References folder in the ContactEmail.Web project. Visual Studio will also make changes to the Web.config file in the same project.

Open the Web.Config file and notice the following items that have been added.

                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                <binding name="ContactEmail.Web.EmailService.customBinding0">
                    <binaryMessageEncoding />
                    <httpTransport />
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
            <service name="ContactEmail.Web.EmailService">
                <endpoint address="" binding="customBinding" bindingConfiguration="ContactEmail.Web.EmailService.customBinding0"
                    contract="ContactEmail.Web.EmailService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

Build the Solution first. Then right click on the EmailService.svc file in the EmailContact.web project. Select "View in Browser" and the following screen should be displayed.




Open the EmailService.svc.cs file and add the following using statement.

Using System.Net.Mail;

Then add the following code:

        public bool SendEmail(String ClientName, String ClientPhone, String ClientEmail, String Comment)
                // BUILD EMAIL MESSAGE STRING //
                string Filler = "";                
                string MsgBody = "";
                MsgBody += "Name:" + Filler.PadLeft(5) + ClientName.Trim() + Environment.NewLine + Environment.NewLine;
                MsgBody += "Email:" + Filler.PadLeft(4) + ClientEmail.ToString() + Environment.NewLine + Environment.NewLine;
                MsgBody += "Phone:" + Filler.PadLeft(4) + ClientPhone + Environment.NewLine + Environment.NewLine;
                MsgBody += "Comments:" + Environment.NewLine + Environment.NewLine;
                MsgBody += Comment + Environment.NewLine;

                string txtEmailTo = "";
                string userName = "UserName";   // WebMaster's user name
                string passWord = "passWord";   // WebMaster's password

                MailMessage msg = new MailMessage();
                msg.From = new MailAddress(ClientEmail);
                msg.To.Add(new MailAddress(txtEmailTo));
                msg.Subject = "*** Contact from Website ***";
                msg.Body = MsgBody;

                SmtpClient smtp = new SmtpClient("");
                smtp.UseDefaultCredentials = false;
                System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential(userName, passWord);
                smtp.Credentials = theCredential;

            catch (Exception ex)
                return false;

            return true;

Remember to change the values in the txtEmailTo, userName, passWord variables. Also, change the line SmtpClient smtp = new SmtpClient(“”) to your web site.

Save the EmailService.svc.cs file and then Build the project. Now right click in References in the ContactEmail Silverlight project and choose Add Service Reference.


Click the Discover button and select the EmailService.svc. Use the Namespace Services and click the OK button.


Visual Studio will add the necessary files to the References folder in the ContactEmail Silverlight project.



Open the MainPage.xaml file and click the Design tab at the bottom of the page.  Right click on the Submit button and select properties from the context menu.

Click on Events – at the top of the properties window – and double click on the Click event.


Add the following using statement in the MainPage.xaml.cs file

using ContactEmail.EmailServiceReference;

Then add the following code:

private void btnSumit_Click(object sender, RoutedEventArgs e)

            Services.EmailServiceClient client = new Services.EmailServiceClient();
            client.SendEmailAsync(txtName.Text, txtPhone.Text, txtEmail.Text, txtComments.Selection.Text);
            client.SendEmailCompleted += new EventHandler<Services.SendEmailCompletedEventArgs>(client_SendEmailCompleted);                                

        void client_SendEmailCompleted(object sender, Services.SendEmailCompletedEventArgs e)
            if (e.Result == true)
                new messageWindow("Title Information", "Email Successfully Sent.").Show();
                new messageWindow("Title Information", "Email Not Sent.").Show();



From the ComtactEmail Silverlight project select Add, New Item.


In the Installed Templates – left panel – select Silverlight. From the center panel, select Silverlight Child Window. Use messageWindow.xaml for the name. Click the Add button to continue.


Add the following code to the messageWindow.xaml file.

<controls:ChildWindow x:Class="ContactEmail.messageWindow"
           Width="400" Height="300" 
    <Grid x:Name="LayoutRoot" Margin="2">
            <RowDefinition />
            <RowDefinition Height="Auto" />
        <TextBox Height="21" HorizontalAlignment="Center" Margin="12,108,20,0" Name="Caption" VerticalAlignment="Top" Width="325" BorderThickness="0" Background="Transparent" />
        <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />

Open the MessageWindow.xaml.cs file and add the following code:

 public MessageWindow(string title, string caption)
            this.Title = title;
            this.Caption.Text = caption;

            // OkButton properties
            this.OKButton.Width = 75;
            this.OKButton.Height = 30;
            this.OKButton.HorizontalAlignment = HorizontalAlignment.Center;

            // Use OK button only
            this.CancelButton.Visibility = Visibility.Collapsed;

Build the solution and hit F5 to run.



Before publishing to a web site, open the ServiceReferences.ClientConfig file – in the ContactEmail Silverlight project – and change the endpoint address to your web site’s address.

Change From:

      <endpoint address="http://localhost:49472/EmailService.svc" binding="customBinding"
       bindingConfiguration="CustomBinding_EmailService" contract="Services.EmailService"
       name="CustomBinding_EmailService" />

Change To:

      <endpoint address="" binding="customBinding"
       bindingConfiguration="CustomBinding_EmailService" contract="Services.EmailService"
       name="CustomBinding_EmailService" />


Build, Publish, and Run!!!