.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

ASP.NET GridView: ‘The Gridview [x] Fired Event RowDeleting Which Wasn’t Handled’

Came across this error today which left me scratching my head for a bit. Basically, I have a Gridview with a Select column, two Button columns, and a few Bound columns.  I gave each button column a unique CommandName property, and one of them was “Delete”, because I was using it to delete the row (I was doing it manually).  I am handling the buttons’ click events in the RowCommand event and discerning which is which by e.CommandName. However, every time I clicked the delete button, I would get the error:

The Gridview [x] Fired Event RowDeleting Which Wasn’t Handled

This struck me as odd, because I wasn’t doing anything with a “RowDeleting” event. I tried putting some random code in there, nothing worked, although the code was getting executed every time. After trying any and everything I could think of, I decided to change the CommandName “Delete” to “Delort” (courtesy of Strongbad 🙂 ) and viola! It worked!

Apparently, the CommandName “Delete” is reserved for the Built-In Editing Functionality of the GridView. I’m sure there are others reserved, too, but I didn’t really look into it any further. Who knew?

Advertisements

August 31, 2007 Posted by | ASP.NET, Errors, GridView, Tips & Tricks | 5 Comments

ASP.NET: How To Get Browser Dimensions?

I’ve run across the issue of how to pull up the browser dimensions without using javascript.  One would think that Request.Browser.ScreenPixelsHeight and .ScreenPixelsWidth would suffice, right?  Well, no. Unfortunately, this only returned 640 x 480 every time I refreshed the page in different dimensions of browser window and at different resolutions.  What exactly does this “640 x 480” actually mean? I can’t seem to put my finger on it. 

It would be nice to know (without depending on Javascript) what the user’s dimensions are for a certain image of which I want to show a blowup using the ModalPopupExtender.  As it is, since the ModalPopupExtender freezes the panel in place regardless of scrolling, if my image is too big, some browsers won’t see everything, so I would like to give users with smaller browsers a scaled-down blowup image.  I suppose a little Javascript to determine these dimensions wouldn’t hurt since they have to have it on to use the ModalPopupExtender anyways, but I try not to depend on Javascript for functionality.  Anyone have any insight?  Thanks!

August 22, 2007 Posted by | ASP.NET, Javascript, ModalPopupExtender | 1 Comment

ASP.NET and Javascript: Accessing Server Side Code?

While writing some code today, I had an idea to improve user experience with a smidge of Javascript. Basically, click on a picture to show its enlarged version (using a ModalPopupExtender), and then on close, run some Javascript to have the appropriate radio button be selected for the image the user just looked at.  No problem, two lines of Javascript, and I don’t even know it that well (although, ASP.NET makes it a pain in the arse to match up control ID’s since they mangle them at run time.  If you’re having problem with ASP.NET changing control ID’s, run your app and check the source code.  Usually your control’s ID is something like “ctl00_somePanel_yourControlID”). 

However, I wanted to run some additional events when certain radio buttons were selected, like hiding or showing certain other panels.  This is easy on the back end, but since I’m already running the ModalPopupExtender, the server side “OnClick” event for the button doesn’t actually fire.  Rather than write some more Javascript to cover all the different permutations of possibilities that could occur, I would rather invoke the server side code once the Javascript has stopped running.  I found this article about Remote Scripting at the Code Project, but it seems far too complex for what I want to do.

Anyone have any ideas on how to call server side code via Javascript?  Or should I just suck it up and have my viewers suffer a postback?  Or better yet, is there a way to get the “OnCheckedChanged” (for the radio button) event to fire from the Javascript, rather than actually calling the server side code?

August 20, 2007 Posted by | ASP.NET, Javascript, ModalPopupExtender | 3 Comments

ASP.NET: How To Easily Reference MasterPage Members

I’ll lay it out very simply:

  1. On your .aspx page, include the following: <%@ MasterType virtualpath="~/myMasterPage.master" %>
  2. To reference the members, simply type Master.Customer or Master.YourProperty

That’s it! It’s better than casting a new master page object for every function, that’s for sure.

NOTE: Content pages load BEFORE master pages, so if you’re going to reference something on your master page, be sure you don’t need it during your content page’s Page_Load event!

August 16, 2007 Posted by | ASP.NET, MasterPages, Tips & Tricks | 35 Comments

ASP.NET: How To Send Email When Your SMPT Server Requires Authentication

I ran into this problem that I simply could not for the life of me figure out.  My main site, www.columbussupply.com, has never had any problems sending email via my usual SMTP server.  However, I have a couple sites using the same host in my account at Successful Hosting (a FANTASTIC webhost, by the way, if for no other reason than the spectacular customer service [no they did not pay me a dime to say this]), and I was having problems with my new site, www.proudwearsports.com, sending email.  The error I kept receiving was:

System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: sorry, that domain isn’t allowed to be relayed thru this MTA (#5.7.1)

After talking with Wade (at Successful Hosting) about my issue, he quickly diagnosed the problem.  Apparently, their server requires authentication (ie, logging in) before sending any mail.  The server was simply not allowing me to send mail from the site without the proper authentication.  So, we went through  my code, and there just wasn’t anywhere in the System.Net.Mail class that would allow me to authenticate the email before I sent it, which had me confused (if there is, in fact, a way to do this programmatically, please correct me!).  But, after a bit of searching I came up with the following magical Web.config code:

<system.net>
  <mailSettings>
   <smtp from=”emailaccountyouaretryingtosendfrom@yourdomain.com”>
    <network host=”whatever.yoursmtphostis.com” password=”yourpassword” userName=”emailaccountyouaretryingtosendfrom@yourdomain.com” />
   </smtp>
  </mailSettings>
 </system.net>

And that’s it!  Once I put that in, the email was sent and everyone went on with their day with a big ol’ smile on their face.

August 16, 2007 Posted by | ASP.NET, Email, Errors, Tips & Tricks | 6 Comments

ASP.NET AJAX Toolkit: ModalPopupExtender Issues in IE6

While working on my newest creation, PROUDWear Sports, I’ve run into a little snag trying to implement the ModalPopupExtender.  Of course it works fine in IE7 and FireFox, but in IE6, it just refuses to work correctly.  I’m pretty sure that I’ve implemented it correctly, but one can never be too sure. I watched the How Do I: Use the ASP.NET AJAX ModalPopup Extender Control video provided by Microsoft and followed it pretty much exactly, except including my own functionality (which is essentially nothing! Basically showing a picture in the hidden panel with a close button, that’s it.) and still it refuses to work in IE6.

I posted in the ASP.NET forums about my issue a few minutes ago, detailing my total problem (6th post down, you can find it by searching for “.NET Discussion”). If you don’t want to go there, basically what happens is in IE6, instead of properly displaying the chosen modal panel, it displays the panel inline with the rest of the page and then goes modal, rendering the page inaccessible to the user.

If anyone has any suggestions, please please let me know.  Thanks!

Status: Solved! (8/17/07)
Solution: Upgrade your AJAX Toolkit DLL. This version is not the newest version, but the ModalPopupExtender functions correctly in IE6 when this one is applied.  I am not using the latest version because the accordion control does not function correctly in the newer versions.  When they fix that, I will go to the newest version.

WHEW!

August 14, 2007 Posted by | AJAX, AJAX Toolkit, ASP.NET, Bugs, CSS, FireFox, IE6, IE7, ModalPopupExtender | 20 Comments

Accepting Drawing Tablet Input Dynamically with ASP.NET

This may be a bit of a stretch, but I was wondering if anyone knew of any way to accept input from a writing tablet and display it dynamically as it is happening, or at least to submit it after you’re done.  If you know how to do this, you are officially a .NET god (or just a computer god).  I suppose this could be used for signing receipts when you pay for something online (and to be honest, I’m sure if this was available, big name companies would already have it) or to play games involving drawing.  If you have any idea how to do this, I would absolutely love to hear it, and you will get full credit on this site (which is getting surprisingly popular as of late, considering how recently I started it).  So get to it!

August 5, 2007 Posted by | ASP.NET, Tablet | Leave a comment