Tuesday, December 15, 2009
Friday, December 11, 2009
Thursday, December 10, 2009
Image Editor Jetpack
Adobe® BrowserLab
Facebook Connect Is Getting Huge
Wednesday, December 9, 2009
Managing UI Complexity | Brandon Walkin
4 things you should track on your blog or website
Google Chrome Extensions
Google Chrome Extensions
Monday, April 13, 2009
Calendar Extender and TextBox set to ReadOnly in C#
Comparison of Political Debate in America and India
Thursday, April 2, 2009
How to implement Cascading dropdowns using JQuery, AJAX and ASP.NET
- Download the zip and set up the application under IIS as an ASP.NET 2.0 virtual directory under the default website
- Open the site in visual studio 2005 and check if you can see all the files as depicted in the solution above
- Open the SendEmailToContact.htm in your browser to run and see the form working
<tr>
<td><select id="DdlContact" name="DdlContact"><option value="loading">Loading contacts...option>select>td>
<td><select id="DdlEmail" name="DdlEmail"><option value="loading">Loading contact emails...option>select>td>
tr>
Observe the following lines in JQUERY,
);
Here, we have appended a Query String to the SendEmailToContact.aspx which will receive the data requests. StrMethodName is checked at the code behind level and if blank, error code -2 is returned. However, in this sample we are not doing any error handling or validation. That will be handled in a subsequent article.
"GETCONTACTS" is a specific text that is matched in the code behind and if found, then the relevant method is called to get the data.
if (!String.IsNullOrEmpty(Request.QueryString["StrMethodName"]))
To: " + strEmail + " Subject: " + " + strEmailMessage + "
Once the data is received from the call, $("#DdlContact").html(response); ensures that the response sent from the server is set into the HTML of the select option (replacing any existing HTML.
html() is a JQUERY function to get and set the innerHTML of an element. To keep the scripting simple, we just created option tags in the server itself and sent it to the calling function.
The next step is to take the selected value of the contacts dropdown, which is the first one by default, and make a similar call for the Emails of the selected contact
Here we had to pass the selected value of DdlContact. The JQUERY function, val() gets the value of selected option.
Note: No matter what way we load the dropdowns, up to about 2000 options it works fine. The moment we start going higher, even though the html is sent within seconds to the client side, the browser becomes sluggish in rendering the drop down. When the options were increased beyond 4000, the browser stopped responding even though response had come back in a few seconds.
Please feel free to post questions / comments for this article at the following link.
Screen shots of the application in action
Initial screen with contact and their emails waiting to be loaded |
On the select of a contact, an AJAX call is made to load the corresponding emails |
Emails are loaded almost instantaneously |
Creating a sample content |
Sample content is received from server in formatted manner |
Wednesday, April 1, 2009
How to submit a form using JQuery via AJAX to an ASP.NET and receive the response
The sample application revolves around accepting some contact details, posting them to an ASP.NET form and then displaying the data received by the server. The sample code can be downloaded from the following zip.
Source: contactmanagement.zip
Solution Screenshot
5. Add default.htm and include the jquery script file and create the form shown in the code snippet (see screenshot)
Monday, March 30, 2009
Recommended strategy for handling exceptions in dot net applications
Purpose of this article
- Take advantage of the good exception handling practices
- To provide a structured approach in handling exceptions
There is a significant amount of debate in my workplace about how much of exception handling is enough and what really should be the scope of exception handling. Without getting into the debate myself, I am going to present my views on the scope, benefits, drawbacks and the most appropriate way of handling exceptions in dot net projects.
Scope
Exceptions are not expected to occur but are known to happen when either there is a flaw in the coding or the system has received data it is not equipped to handle. Professed exceptions that are raised within code due to foreseen circumstances such as, duplicate record entry, etc should not stop the program execution. The user should be displayed an appropriate warning message and allowed to take corrective action. The true exceptions should be,
- Logged at the first occurrence location into a log file
- A new custom exception with only those exception details that may be used within the code and the exception class inheriting from ApplicationException should be created and rethrown.
- This custom exception should be caught and rethrown across all levels till we reach an event handling method (e.g.: catch(CustomException) { throw; }.
- The user should be redirected to an error page which displays some summary details of the exception and any standard message to the user that may suit the need of the application.
- The same error page could allow the user to bring this exception to the notice of a designated authority (maybe a web admin) via email created in a rich text environment (also allowing snapshots to be attached). This is important if the exception can keep occurring every time the user revisits the involved activity keep the user from carrying on with his / her tasks. However, this may be more useful in the case of intranet applications. Public portals could cause a deluge!
Details that should go into an Exception and its message
Typically, there are two kinds of exceptions that will occur. The first kind is thrown by the system and the second kind is thrown from the code. In the former case,, post logging, you should replace it with your own exception object (inheriting from ApplicationException class).
In the case of your wanting to throw an exception, the message should contain the following information,
- The method name which first caught / invoked the exception.
- The class name (whether it’s a web page or windows form or a library class) which contains the method mentioned in point 1.
- Some details of the cause of exception / the activity that has been affected by this exception.
Additional information may be provided as per the application requirements.
Proposed Framework for Exception Handling in an Application
- Catch and throw exceptions as proposed in the above sections
- Log the exception to a log file the first time it is caught
- Display a user expectation friendly error page when exceptions occur giving the facilities mentioned above
- Run a background service that periodically clears the log file entries and transfers them to a database for analysis of application state. Alternatively, you can log the exceptions to a database straight away and keep the log file as a backup plan incase the database is unresponsive.
Footnote
The details mentioned so far are more with respect to dot net (c#, vb.net, asp.net) applications and specific applications, especially scientific or time critical applications may require a different approach to exception handling. I am sure that there may be scenarios / options / issues that have not been mentioned explicitly in this article. Anyone contributing to this article would be appreciated. I am also more than willing to provide further information on specific questions.