asp.net

  • Visual Studio 2010 versus COM-Object fails

    I spent ages trying to find a solution to this issue after upgrading to VS2012. This link solved the problem and stopped me returning to VS2005. Why Microsoft, why? Thank you malamsson.

    Know More

  • Launch the Debugger Automatically

    The following is taken directly from msdn : How to: Launch the Debugger Automatically Sometimes, you may need to debug the startup code for an application that is launched by another process. Examples include services and custom setup actions. In these scenarios, you can have the debugger launch and automatically attach when your application starts.…

    Know More

  • Close a Parent Form from Child Form

    From a child form I wanted to close the parent form after a button was clicked, the following is the code I used: // In the child form, create an event that indicates the special occurrence.public event EventHandler Special;protected virtual void OnSpecial(EventArgs e) { EventHandler Handler = Special; if (Handler != null) Handler(this, e);}// Perhaps…

    Know More

  • Rich ajax applications that do not break if javascript is disabled.

    This is a great solution for dealing with checking whether the clients browser has JavaScript enabled/disabled, and then coping with either scenario: Rich ajax applications that do not break if javascript is disabled.

    Know More

  • “System.OutOfMemoryException: Out of memory” When using Image.FromFile(imageFile)

    When I was populating an System.Drawing.Image object from a folder of images I revceived the following error message:“System.OutOfMemoryException: Out of memory”At first I thought I had a very large image in this folder, but realised after reading the blog post:Image.FromFile(“…”) and System.OutOfMemoryException,that I had a file in the folder that was not an image type…

    Know More

  • Multiline TextBox Maximum Character Validation

    Maximum character validation on asp.net TextBox controls do not work, therefore a RegularExpressionValidator has to be used to make sure the maximum number of characters are not exceeded e.g. <asp:TextBox ID=”tbAbstract” runat=”server” Text='<%# Bind(“Abstract”) %>’ Rows=”5″ TextMode=”MultiLine” MaxLength=”4000″/><asp:RegularExpressionValidator ID=”valAbstract” runat=”server” EnableClientScript=”false” ControlToValidate=”tbAbstract” Text=”Abstract exceeds 4000 characters” Display=”Dynamic” SetFocusOnError=”true” ToolTip=”Abstract must not exceed 4000 characters” ValidationExpression=”^[sS]{0,4000}$”…

    Know More

  • Strip HTML Tags from a String using Regular Expressions 

    Whilst writing some code to search forum posts I had the reason to remove all HTML tags from the forum posts before I could do a valid phrase search. I created the following function: public static string StripDecodeHtml(string content){  content = HttpUtility.HtmlDecode(content);  string myTagPattern = @”]*>(?<text>.*?)“;  Regex myTagRegex = new Regex(myTagPattern, RegexOptions.Compiled          |RegexOptions.IgnoreCase|RegexOptions.Singleline);  // do until no more tags…

    Know More

  • Examples of Regular Expressions

    Trim string in JavaScript var trimre=’^s+|s+$’; // replace whitespacevar trimmedstring = string.replace(trimre,””); Check for a valid date format in JavaScript var re=’^(d{1,2})/(d{1,2})/(d{4})$’; // dd/mm/yyyyif (!datestring.match(re)){ alert(“Date” + datestring + ” not in valid dd/mm/yyyy format”);}else // valid date keyed in{ …valid date keyed} More to follow…

    Know More

  • Creating a Banned Words Filter

    I have a website with a user forum and content management system, where certain users (or anyone in the case of forums) can post to. I therefore had to create an easy way to filter and change certain naughty/controversial words from being viewed on my pages. I wanted the solution to be easy to maintain…

    Know More

  • Insert JavaScript before PostBack Event

    To call some javascript before the postback event is raised, use the following code: if (!Page.ClientScript.IsOnSubmitStatementRegistered(type, “script_onsubmit_editor_” + ClientID)) {   string popTextareaScript =      “var ed = YAHOO.widget.EditorInfo.getEditorById(‘” + editor.ClientID + “‘);”      + “ed.cleanHTML();”;    Page.ClientScript.RegisterOnSubmitStatement(type,       “script_onsubmit_editor_” + ClientID, popTextareaScript); } In the above code example I was trying to populate a textarea from the YUI Editor.

    Know More

  • Debugging JavaScript with Visual Studio.net

    The following piece of advice was taken from a blog (click here to see original) discovered while I was searching for a solution to debugging JavaScript in Visual Studio.NOTE: Currently only works is IE, I have not investigated using Firefox. ASP.Net makes it very easy to write and debug server side code. I’ve found when…

    Know More

  • Styling Buttons in IE

    Even though the button had a class specified on it to change the background image, in IE7 this did not style the button (but in Firefox the styling was picked up from the CSS class “Button”) e.g.and the CSS class was: .Button, input[type=”submit”], input[type=”button”] {   background-position: center center;   background-image: url(Images/ButtonImage.gif); } Solution:The default styling on the IE…

    Know More