Navigation


RSS: Matt Pavey RSS Feed



Thursday, January 22, 2009 @ 9:17 am,ASP.Net,Matt Pavey

Another great article on ScottGu's Blog.

Microsoft recently released a cool new ASP.NET server control - <asp:chart /> - that can be used for free with ASP.NET 3.5 to enable rich browser-based charting scenarios:

Check out the article for more information on dowloading the free chart control, samples and documentation:

http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx

"<asp:chart /> supports a rich assortment of chart options - including pie, area, range, point, circular, accumulation, data distribution, ajax interactive, doughnut, and more.  You can statically declare chart data within the control declaration, or alternatively use data-binding to populate it dynamically.  At runtime the server control generates an image (for example a .PNG file) that is referenced from the client HTML of the page using a <img/> element output by the <asp:chart/> control.  The server control supports the ability to cache the chart image, as well as save it on disk for persistent scenarios.  It does not require any other server software to be installed, and will work with any standard ASP.NET page."


Tuesday, November 18, 2008 @ 7:32 pm,ASP.Net,Matt Pavey

Here's an easy way to check or uncheck all items in a CheckBoxList.
 
 
JavaScript
 
function CheckBoxListSelect(cbControl, state)
{
     var chkBoxList = document.getElementById(cbControl);
     var chkBoxCount = chkBoxList.getElementsByTagName("input");
 
     for(var i=0; i < chkBoxCount.length; i++)
     {
          chkBoxCount[i].checked = state;
     }
 
     return false;
}
 
ASP.Net CheckBoxList
 
<div>
     <a href="javascript:void(0)" onclick="javascript: CheckBoxListSelect('<%=chkStates.ClientID %>', true)">Select All</a> | <a href="javascript:void(0)" onclick="javascript: CheckBoxListSelect('<%=chkStates.ClientID %>', false)">Select None</a>
</div>
 
<div>
     <asp:CheckBoxList ID="chkStates" RepeatColumns="6" Width="100%" runat="server" />
</div>


Thursday, May 22, 2008 @ 9:47 am,ASP.Net,Matt Pavey

"In this article we saw how to add a "Check/Uncheck All" header CheckBox to the GridView that, using client-side techniques, provides a means to quickly check or uncheck all row-level CheckBoxes. The header CheckBox, along with the "Check All" and "Uncheck All" buttons, provide the user with multiple ways for checking or unchecking all of the grid's CheckBoxes. Since client-side script is used to handle checking and unchecking the CheckBoxes, the interface provides a snappy user experience."

http://aspnet.4guysfromrolla.com/articles/053106-1.aspx


Saturday, September 15, 2007 @ 6:47 pm,ASP.Net,Matt Pavey

Here's a great article on master pages.
 


Saturday, September 15, 2007 @ 12:19 pm,ASP.Net,Matt Pavey

Enter Key functionality is handled a little differently when it comes to ASP.NET. 
 
If there is a single button then it is straight forward because that button is the only button and thus the default button; however, if there are two or more buttons then it uses the first button as the default button.
 
ASP.NET 2.0 introduces a work around for this by simply specifying the defaultbutton property to the ID of the <asp:Button> whose event you want to fire.
 
The defaultbutton property can be specified in the <form> tag as well as in the <asp:panel> tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel.
 
If for some reason handling this at the form level or panel level doesn't fit with how you have things setup, you can still use some simple JavaScript techniques to accomplish this.
 
Take this JavaScript function for example, which also utilizes another custom FindControl function.
 
function Submit(e, ButtonName)
{
    
var KeyCode = (window.event) ? event.keyCode : e.which;
     var KeyChar = (window.event) ? String.fromCharCode(event.keyCode) : String.fromCharCode(e.which);

    
if (KeyCode == 13)
    
{
         
var btnSubmit = FindControl(ButtonName, "input");
         
          if(btnSubmit != null)
         
{
              
btnSubmit.click();
          
}
 
          if (window.event)
          {
               window.event.returnValue = false;
          }
         
else
         
{
              
e.preventDefault();
          
}
     }
}
 
Now for any control on your page you can specify which button you want "clicked" when the ENTER key is pressed while that control has focus like so:
 
<asp:TextBox ID="txtTest" onkeypress="Submit(event, 'btnSubmit')" runat="server" />
 
This has been tested in IE and Firefox.


Saturday, April 14, 2007 @ 5:44 pm,ASP.Net,Matt Pavey

I ran into an issue the past couple of days regarding prompting the user with a OPEN/SAVE prompt for exporting data. It's been working for as long as I can remember, but yesterday I upgraded the site to use an SSL certificate so everything would be secure. But in doing so the OPEN/SAVE prompt for one of my pages no longer worked and was causing an IE error.

Further research confirmed that there are some known IE bugs regarding setting the ContentType and Content-Disposition to support forcing an attachment to be streamed directly to the user via the OPEN/SAVE prompt, opposed to having to actually save the file to disk and worry about disk space, permissions, etc.

Anyways, since it took me a while to pin down getting this to work with HTTPS (SSL) I thought I'd go ahead and share the code in case anyone else ran into the same thing.

Response.ClearHeaders()
Response.ContentType = "application/csv"
Response.AppendHeader("Content-Disposition", "attachment; filename=Registrations.csv")

The Response.ClearHeaders() line was the line I had to add to solve the problem.

Apparently this is only a problem with IE browsers and I saw several posts about it and all of them had different solutions proposed, such as setting the Pragma and other header related values, but I couldn't get any of those to work. So I thought if I couldn't change the header values I would simply just clear them all out and set exactly what I needed, which was the ContentType and the Content-Disposition.

After adding that single line of code the page now works for HTTP and HTTPS and from my testing works in all major browsers (IE, Firefox, etc.).


The opinions expressed on this website are my personal opinions
and do not represent my employer's or my clients' views in any way.