- 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 |
No comments:
Post a Comment