Sometimes we want to render just a control into the client browser using native ajax (I mean, without atlas or ajax extensions), but it's not as easy as you could think... For example, if you have to render a GridView alone, without another html information you will probably see some unknown exceptions...
- 1st try The first thing I made was create an empty aspx page (with no html tags) and add a GridView, but oops!, when I runned it, asp.net throws a exception saying that all the controls need to be inside a html <form>... It has sense, so close IE and try again...
- 2nd try Ok... Now I already added the <form> tag into the aspx page, opened it into the browser and everything works great. But wait!, I still haven't the ajax part written.... it's not hard to do, I just have to create a XMLHttpRequest in javascript and write the response into a <div>.. When I run the page containing the ajax script, IE throws a 'Unknown Error' exactly where i write the response to the Html, something like this: div_element.innerHTML = req.responseText; After a while I suppose that a <form> tag cannot be placed inside another one... but, should I go back to the 1st try and remove the <form> element?
- 3rd try - The real "hack" So, I need to remove the <form> element, but ASP.NET don't allows that, so it's time to use the Lutz Roeder's Reflector.. Inherit from Page class and remove this validation, it's simple:
public class AjaxPage : System.Web.UI.Page { public override void VerifyRenderingInServerForm(Control control) { if ((this.Context != null) && !base.DesignMode) { if (control == null) { throw new ArgumentNullException("control"); } } } }
Now you can run and see everything working, or I hope so...
Comments
Post a Comment