Tuesday, March 24, 2009

getElementById compared in IE6, IE7 and IE8

Hi guys!

These days I was enjoying the new Internet Explorer 8 and were observing the differences with the previous versions of the browser.

I encountered a problem connected with the getElementById method. It was working OK in IE6 and IE7, and now in IE8 it suddenly stopped working.

How does getElementById works in IE6/IE7
In IE6 and IE7, the method getElementById would get an element provided either the ID or the Name attribute of the element. What is more, it matches it case-insensitevily.


In Comparison
In IE8 it does exactly what it says and what it should do - it gets the element only by the ID attribute and it matches case-sensitively.

Conclusion
The reason why the old code wasn't working in IE8 was because someone has used the getElementById to get an element on the page provided it's Name. Which apparently won't work in IE8.

More on this
More on this, Here (Check the Remarks paragraph)

Friday, March 20, 2009

asp:FileUpload control in Modal Popup Extender

Hello guys !

Let's go straight to the issue this time.
I have a Modal Popup Extender and want to use the standard FileUpload control in it. What I mean by saying the "standard FileUpload" control is that I will use the asp:FileUpload control and not the AJAX-enabled one which is in the AJAX Control Toolkit.

What's the issue/problem?
The problem is that the AJAX makes partial updates and doesn't perform a full postback. The FileUpload control itself works with full postback - in the postback the File which you uploaded is attached in the Request.Files collection. So, when you are not performing a full postback, the file is not uploaded in the Request.Files collection and you cannot get the file to use it - for saving in the database for example.

The solution
The Script Manager has one very useful method - RegisterPostBackControl ( http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerpostbackcontrol.aspx ). It basically registers a control, which should implicitly do a full postback. In my case, it was enough just to register the FileUpload holding control to perform a full postback and I had the File uploaded into the Request.Files and ready for use.


Conclusion
The issue and the solution were pretty straight-forward this time. But it can become trickier, if you don't know the RegisterPostBackControl method.

Wednesday, March 4, 2009

ASP.NET Validator in Modal Popup Extender

Yesterday,
I had an interesting issue, which I want to share with you.

The Case
I had a RequiredFieldValidator in a Modal Popup Extender. After closing the popup, everything in my web page freezed. For example, clicking a LinkButton/Button wouldn't do a postback, everything just stopped working.

The Problem
After some kind of debugging, I figured out the problem. As you know, the modal popup extender works like this:
1.) When you invoke the .Show() method of the Modal Popup Extender, the AJAX.NET takes the PopupControl you want to Show as a popup and brings it to the front.
2.) When you invoke the .Hide() method or close the Modal Popup Extender from a button inside it, it again takes the PopupControl and hides it in the page.
So, the problem I encountered was, that when the user entered some invalid data and presses the cancel button(to close the ModalPopupExtender and to cancel the changes), the AJAX.NET hided the PopupControl in the page. The problem was, that the RequiredFieldValidator was yielding that there is invalid data, so it was blocking all the postbacks. The cute thing is, that you can't actually see the RequiredFieldValidator, because it's in the Modal Popup which you don't see, too.

The Solution
The simplest thing to do, was to clear all the Validators from the ModalPopupExtender, when I hide it. This is not a neat solution for me, but I don't know any better for now.

Conclusion
Probably, people encounter such a 'problem' on rare occasions, but I found it useful for myself, and will be aware of this.