CheckBoxList Select All Extender and Spore

Before I get to any code, I just wanted to point out that Spore is coming out on September 7... So if you come to the site and haven't seen an update after that date, you'll know why.

Anyway, on to the code. This one is rather basic (as most of the extenders I create are), but I haven't seen anyone else coming out with extenders to do similar tasks. Either that or the ones I do find, I don't really like for one reason or another. In this case, all I wanted was a button that I could click on and have all of the various check boxes in a CheckBoxList be checked. And if they're all checked, to uncheck them all... That was it really.

CheckBoxSelectAllExtender.zip (1.82 kb)

My code is extremely basic in this instance, but allows you to switch the text of the button based on the state that it's in. Otherwise, not much really to it. Just specify the TargetControlID as the button you want to use, the CheckBoxListID to the CheckBoxList, the select all and deselect all text, and you're good to go. So if you want to go in and modify the code, feel free. I will warn you that the CheckBoxListID points to the list, but the list is rendered as a table. So in order to get the actual check boxes from it, you need to use getElementsByTagName("input"). It's pretty straight forward from there, but keep that in mind. Anyway, download the code, give it a try, and happy coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 8/19/2008 at 11:26 AM
Tags: , ,
Categories: AJAX | ASP.Net | Web Design
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Server side validation in ASP.Net

One of the items I was extremely happy to have before me when I switched to ASP.Net was the various validators. The fact that I didn't have to write my own code, nor use a third party library to accomplish validation of user entered information was fantastic. The main issue though is the fact that they're all client side. This means that while you can make sure the data is in the correct format, you can't check to see if the information already exists, if it points to a valid location (fake email/urls), etc. without a post back.

The post back gets rather annoying though for the end user, but thankfully there's AJAX. Thanks to AJAX, we have a couple of options: using UpdatePanels, AJAX calls, or building an extender. And since I'm lazy and like to reuse everything (not to mention I wanted the item to run with decent speed), I created a very basic extender.

ServerSideValidatorExtender.zip (2.14 kb)

The version here is extremely basic and can definitely be improved upon. However it takes in a control and when it is changed, it does a call back to a function specified with the value within the item. The function returns a boolean value (true if the value is OK, false otherwise) and displays an error message as needed. Once again, it's extremely basic and could use some extra features (such as displaying something during the call, maybe an option for success text, etc.). Anyway, download it, try it out, leave feedback, and happy coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 8/13/2008 at 2:38 PM
Tags: , ,
Categories: AJAX | ASP.Net | Web Design
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

File Uploads and UpdatePanels

ASP.Net's implementation of AJAX is pretty good with a couple of exceptions. Most of the issues are related to speed when it comes to UpdatePanels. However the issue that I'm going to bring up today is the fact that you can't place a FileUpload component inside of one.

The reason for this issue is pretty simple, you have to have a full post back in order to upload a file and javascript can't access files (well not without ActiveX, etc.). So what do we do? Well assuming that you can't move it out of the UpdatePanel for whatever reason, we have two options really. The first option is to register the item for full post back:

 

ScriptManager.GetCurrent(Page).RegisterPostBackControl(NameOfUploadControl);

 

This is rather simple, but does cause a full post back. If that isn't an issue for you, then it's probably the easiest route to go. The second option is to put the FileUpload control (or input control) inside an iframe. In order to do this, we require two files obviously. All page one needs to include is:

<iframe src="Page2.aspx"></iframe>

Obviously you'd want to set the width, etc as needed but that's it. The second page would then house the FileUpload control and a save button (note that you can also have the first page update the iframe and on post back have the second page save the file, but I'm just showing the easiest solution here). The second page then saves the item. So basically you'd have:

 

<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

 

for the front, and this for the back end:

 

        protected void Button1_Click(object sender, EventArgs e)
        {
            FileUpload2.SaveAs("FileName");
        }

 

Note that you'd want some basic file checking, etc. in there but I'm just showing you the basic concept. Anyway, that's all there is to it. I'm currently using the second method to come up with an AJAX friendly system that will allow multiple file uploads and show the current progress.  When that's ready I'll be sure to post it here. Anyway, try out the code, leave feedback, and happy coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 8/11/2008 at 11:17 AM
Tags: , , ,
Categories: AJAX | ASP.Net | Web Design
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed