CameTooFar A Nerd's False Positive

ASP.NET - Launch debugger programmatically using debugger.launch

8. June 2012 06:34 by abhilashca in Debugging, ASP.NET, Javascript, Classic ASP


For last few months, I’s working in a large scale project which runs both Classic ASP and ASP.NET in parallel. While debugging, we used Attach Process of Visual Studio 2010 to attach w3wp.exe. But for some reason, the process was not attaching and I’s unable to debug my application.

After hours of digging, I came across a nice workout. You can programmatically launch the debugger as below:

using System.Diagnostics;
 
// launch the debugger and attach to current process
Debugger.Launch();

As a side-note, for Classic ASP/VBScript use stop keyword and for Javascript use debugger;

Note: What I have mentioned is only for testing/debugging purpose and do remove the above code before moving to production server.

Happy debugging!

Thanks.

Regular expression validator firing after postback in asp.net

22. April 2012 08:52 by abhilashca in ASP.NET


As usual, I’s really surprised to see what had happened when I attach a regular expression validator to one of my fileupload control. The regular expression validator was firing after every successful fileupload. Yup! The solution is way too simple. Simply, set the IsValid property of the regular expression validator to true.

protected void btnAddDocument_Click(object sender, EventArgs e)
{
//
// your logic comes here
//
 
    regexvalUploadDoc.IsValid = true;
}

That’s it.

ASP.NET Menu rendering issue in Google Chrome

27. March 2012 21:09 by abhilashca in ASP.NET, Controls

 

Now, that was weird!

Surprisingly, I jumped into a rendering issue with ASP.NET menu in Google Chrome and I observed following glitches:

  1. Sub-menu items were not displaying on hovering over the main menu (say Products)
  2. When I select the main menu item (Product), the respective sub-menu items are displayed horizontally, instead of listing vertically (on hover)

Here goes a sample screenshot

menu_issue

The solution is to check for Chrome user-agent string and clear the browser adapter mapping so that the control will be rendered irrespective of the client browser.

if (Request.UserAgent.IndexOf("Chrome") > 0)
{
if (Request.Browser.Adapters.Count > 0)
    {
        Request.Browser.Adapters.Clear();
        Response.Redirect(Page.Request.Url.AbsoluteUri);
    }
}

The ControlAdapter provides a mapping between an ASP.NET Web Control and the adapter used to render the control in client browser.

If you are interested to dig deeper, then have a look at here and here.

Best way to use this code is to create a Base class inherited from System.Web.UI.Page and include this code in appropriate page event. Now, you can inherit this base class is those pages that require this piece of code.

Note: After clearing the Adapter for Chrome, I haven’t experienced any issues with other web controls so far. In case, if you are facing any issue, please feel free to share it.

Thanks