ASP.net Archives - Page 3 of 4 - Digital Tool Factory blog

The Digital Tool Factory Blog

How to fix the Asp.net CalendarExtender and CompareValidator to accept European date formats

The Problem: You want to use the standard European Date Format, DD/MM/YYYY instead of the American Date Format MM/DD/YYYY.  You change the “Format” feature of the CalendarExtender to “DD/MM/YYYY”, but then the CompareValidator (which you’re using to ensure valid dates) calls out that you have entered an invalid date.

The Cause: The Compare Validator is expecting a different date format than it receives, and throws the error.   You will then notice that there is no “Format” attribute on the CompareValidator.

The Solution: Add the following line to the System.Web portion of your web.config file.

<globalization culture=”fr-FR”/>

That’s it!

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


01
Oct 10


Written By Steve French

 

How to fix problems with the placeholder control and custom web user controls

The Problem: You are using an asp.net PlaceHolder control and populating it with a collection of custom web controls.  You then get “Null Reference Exception” and “Are you missing an assembly?” errors.  Your code looks much like this

foreach (string str in strStringList)
{
CustomWebBox cb=new CustomWebBox()[
cb.CustomTitle=str;
myPlaceHolder.Controls.Add(cb);
}

The Cause: The same ID’s are being used over and over agian in the page as the web control repeats.

The Solution: Instead of simply reinitializing the control the “new” keyword, load it manually using Page.LoadControl.  That keeps the id tags different and the error is avoided.  Your code would look something like this.

foreach (string str in strStringList)
{
CustomWebBox cb=(CustomWebBox)Page.LoadControl("~/CustomWebBox.ascx");
cb.CustomTitle=str;
myPlaceHolder.Controls.Add(cb);
}

That’s it!

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


27
Sep 10


Written By Steve French

 

How To Fix Column Doubling in an ASP.net GridView – with Code Sample

Chocolate Tools
The Problem: You are trying to create an ASP.net GridView that automatically populates on any dataset, as well as automatically sorts, but for some reason whenever you click the headers to sort the GridView, the data doubles.

The Cause: I originally omitted crucial line
gv.Columns.Clear();

in the code sample below.    For whatever reason I got it stuck in my head that the data was doubling, not the columns.

Continue reading →


31
Aug 10


Written By Steve French

 

CSS trick – how to use two classes on a single DOM object

I have no idea how this trick has eluded me for so long, but it is possible to use two classes on the same DOM object.  For example to combine a class called “TopNav” and a class called “SelectedNav” all you have to do is call them both with code like this

<div id=”HomeNavItem” class=”TopNav SelectedNav”>Home</div>

In other words, you’re just putting them in the same class declaration.  I’ve been doing this for years and I’ve never done that before.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


13
Jul 10


Written By Steve French

 

A simple way to create a Microsoft Word document from a template in Asp.net/C#

Will code for food I recently had the need to create a Microsoft Word document from a template. I initially tried using Office Web Components and Interop but all that really wasn’t worth the trouble.  I wound up doing global replacements in the html of html   Here is how I did it:

  1. Open up your template document in word, and put any target areas in special Brackets, the text would read something like “I, [FULLNAME] do hereby affirm that”.  I found that the target area had to be in uppercase, I’m not sure why
  2. Go to “Save As Html, Filtered”, and save it in a writeable directory.
  3. In your C# code, first load the entire document into a string
  4. Convert that string into an instance of StringBuilder
  5. Use the StringBuilder Replace function, it would look something like this –  sb.Replace(“[FULLNAME]”, strFullName);
  6. Create a TextWriter, and write the StringBuilder to it – make sure you’re saving it with a “.doc” extension.
  7. Close the TextWriter

All told, the code looks like this

//Create a new filename
string strFileName = System.Guid.NewGuid().ToString();
string strPathRoot = “d:domainsMyDomainWord”;
string strPath = strPathRoot + “TemplateHtml.doc”;
string str = System.IO.File.ReadAllText(strPath);
StringBuilder sb = new StringBuilder();
sb.AppendLine(s);
//replace the text
sb.Replace(“[FULLNAME]”, strFullName);
//save it out
TextWriter tw = new StreamWriter(strPathRoot + strFileName + “.doc”);
// write a line of text to the file
tw.WriteLine(sb.ToString());
// close it
tw.Close();
tw.Dispose();

That’s it!

Creative Commons License
photo credit: pvera

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


06
Jul 10


Written By Steve French

 

How to fix the “The service cannot be activated because it requires ASP.NET compatibility” error

The Problem: You try to access your web service on IIS 7 and you get the following error

The service cannot be activated because it requires ASP.NET compatibility. ASP.NET compatibility is not enabled for this application. Either enable ASP.NET compatibility in web.config or set the AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode property to a value other than Required.
at System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateCompatibilityRequirements(AspNetCompatibilityRequirementsMode compatibilityMode) at System.ServiceModel.Activation.AspNetCompatibilityRequirementsAttribute.System.ServiceModel.Description.IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase) at System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost) at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) at System.ServiceModel.ServiceHostBase.InitializeRuntime() at System.ServiceModel.ServiceHostBase.OnBeginOpen() at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open() at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath) at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)

Continue reading →


15
Jun 10


Written By Steve French

 

How to Fix: Canonical Urls with IIS 7’s Url Rewrite feature for https

SATOR Magic squareThe Problem: You want to make your website all SEO friendly by creating a single, canonical url.  For example, if someone types in http://www.stronico.com, you want them to be redirected to http://stronico.com (Google likes it this way).  You do some research and discover that all of the default code and documentation for handling canonical Urls in IIS 7 uses web.config files and the URL Rewrite application program.  All is well and good so far, but what if you use SSL?  The stock code will always redirect you to http://stronico.com/Signup/ even if the original url was https://stronico.com/Signup/ (note the https). Continue reading →


01
Jun 10


Written By Steve French

 

How to fix updating problems in your Silverlight application

The Problem: You make changes to your Silverlight Application, but you do not see it reflected when you debug or run the solution.2cv_phil_repair_small

The Cause: While the web project portion of the solution is being compiled and run, the Silverlight project is not being built.  This just happened to me recently.  Visual Studio crashed and somehow the Silverlight project portion of the solution decided to remove itself from the build list.

The Solution: Right-Click on the solution, then select “Configuration manager”.  Make sure that the “Build” checkbox is selected for both projects.  That’s it!

Creative Commons License photo credit: Mooganic

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


02
Mar 10


Written By Steve French

 

How to fix strange errors in silverlight web services

fix you_smallThe Problem: You upload your wonderful Silverlight application to a new server and begin to get all sorts of strange errors, most notably something like this

Message: Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.   at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at StronicoMain.ServerUtil.AddressTypeListCompletedEventArgs.get_Result()
at StronicoMain.Page.proxy_AddressTypeListCompleted(Object sender, AddressTypeListCompletedEventArgs e)
at StronicoMain.ServerUtil.ServerUtilClient.OnAddressTypeListCompleted(Object state)
Line: 1
Char: 1
Code: 0
URI: http://www.servername.com/Silverlight.js

Continue reading →


02
Mar 10


Written By Steve French

 

How to fix the No connection could be made because the target machine actively refused it 127.0.0.1:25 error

The Problem: You have a brand new Windows 2008 server and you are testing your web application and trying to send an email.  Every time you try to send an email via the web application you get the following error

“System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25”

The Cause: SMTP services are not installed on the server, they do not seem to be installed by default. Continue reading →


12
Feb 10


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.