Perform ASP.NET Postback using JQuery
Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback. Firstly, add the following JQuery/Javascript code: <script> function autoSubmit() { <%= ClientScript.GetPostBackEventReference(btnSaveChanges, "") %>; } [...]
Using UserControl.RenderControl()
Perhaps you want to reuse a usercontrol in a email? or you need to generate the html from a usercontrol for a specific purpose? Firstly, here is the code to render the html from a user control to a string builder object: Dim sb As New StringBuilder() Using sw As New StringWriter(sb) [...]
Back to Basics – Deleting Cookies using ASP.NET
You cannot instruct ASP.NET to physically remove cookies from the user’s computer so you have to tell the user’s browser to modify the cookie in order to trigger the browser to remove the cookie. See code example: HttpCookie aCookie; string cookieName; int limit = Request.Cookies.Count; for (int i=0; i { cookieName = Request.Cookies[i].Name; aCookie = [...]
Detect when a session has ended ASP.NET
A problem that I have had in the past is trying to find out when a session has expired within ASP.NET and how to deal with the expired session. One solution is to add the following code into the Page_Init event. You can add this event into a class that inherits the Page class so [...]
Could not load file or assembly ‘NameOfAssemblyGoesHere’
Encounted the following error: Could not load file or assembly ‘NameOfAssemblyGoesHere’ or one of its dependencies. An attempt was made to load a program with an incorrect format. The problem happened when deploying a web application to a 64bit server where all the required DLL’s where marked as running only on a 32bit system. You [...]
Change username in ASP.NET Membership Provider
Found a great article here about the process of changing the username with the ASP.NET Membership Provider. Here is a summary of the process that I found best useful which is one of the comments: 1. Make sure New UserName is Unique 2. Update the aspnet_Users table directly 3. Execute to following code to change [...]
DateTime.ToString()
Here is a link that is useful as a reference for DateTime.ToString patterns References: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm
Using the HttpWebRequest class
In this particular scenario I had to initiate a request from another website in code and track its response to be modified and rendered back to the user. I had a series of LinkButton html controls on the web form that consume one event. <asp:LinkButton id=”link1” runat=”server” onClick=”genericEvent”></asp:LinkButton> When the user clicks on a particular [...]
Using ASP.NET MVC on IIS6 or below
When you are building a web applicatio using the ASP.NET MVC framework on IIS7, it URL routing works smoothly and without any dramas. But when it comes to IIS6 you have to make a comprimse especially if you are developing web apps within a shared hosting envoirnment. I found the easist way is to change [...]
W3C Validation and ASP.NET ViewState
The problem I came across a very interesting point about validating XHTML pages using W3C XHTML Strict and ViewState. By default ASP.NET ViewState adds a number of hidden fields to handle the postback of ASP.NET pages, control state and control event validation. See example below. <input type=”hidden” name=”__VIEWSTATE” id=”__VIEWSTATE” value=”” /> When validating web pages [...]


