Friday, November 13, 2009

Firebug for IE and chrome

Installing Firebug

Just add this code into any page that you want to contain Firebug lite:

Thursday, October 30, 2008

How to call javascript function on userControl load ?

One way to do this is
Register StartUp script on pageload of your usercontrol

Page_Load()
{
ClientScript.RegisterStartupScript(this.GetType(), "onlo", "YourMethod();",true);

}

Another way is
call your method on window.onload

Tuesday, January 29, 2008

Master Page To Content Page Interaction

Here is a case where the master part of the master page name can be misleading. The master page sounds like a good place to put logic and code that will tell the page how to do something. After all, a master page is the master, right? We now know that the master page is just another child control. Ideally, the master page will remain passive. Instead of telling it’s parent page what to do, the master page should tell a page when something interesting happenes, and let the page decide what to do.

Let’s pretend every page in our application displays a report, and every page needs a button for users to click and email the report. Putting a Button and a TextBox inside the master page seems like a reasonable choice.

< asp:TextBox runat="server" id="EmailAddressBox" />
< asp:Button runat="server" ID="SendEmailButton"
OnClick="SendEmailButton_Click" />

What happens when the user clicks the button? We can choose from the following options:

* Handle the Click event in the master page, and have the master page email the report.
* Expose the Button and TextBox as public properties of the master page, and let the content page subscribe to the click event (and email the report).
* Define a custom SendEmail event, and let each page subscribe to the event.

The first approach can be ugly because the master page will need to call methods and properties on the page. Master pages are about layout, we don’t want to clutter them with knowledge of reports and specific pages.

The second approach is workable, but it tightly couples the page to the master. We might change the UI one day and use a DropDownList and a Menu control instead of a TextBox and Button, in which case we’ll end up changing all of our pages.

The third approach decouples the master page and content page nicely. The page won’t need to know what controls are on the master page, and the master page doesn’t have to know anything about reports, or the content page itself. We could start by defining the event in a class library, or in a class file in App_Code.

using System;

public class SendEmailEventArgs : EventArgs
{
public SendEmailEventArgs(string toAddress)
{
_toAddress = toAddress;
}

private string _toAddress;
public string ToAddress
{
get { return _toAddress; }
set { _toAddress = value; }
}

}

public delegate void SendEmailEventHandler(
object sender, SendEmailEventArgs e);

We can raise this event from a master page base class (if we have one), or from the master page itself. In this example, we will raise the event directly from the master page.

< %@ Master Language="VB" %>

< script runat="server">

Public Event SendEmail As SendEmailEventHandler

Protected Sub SendEmailButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)

Dim eventArgs As New SendEmailEventArgs(EmailAddressBox.Text)
RaiseEvent SendEmail(Me, eventArgs)

End Sub

< /script>



We'll need to add some validation logic to the master page, but at this point all we need is to handle the event in our page. We could also handle the event from a base page class, if we don’t want to duplicate this code for every page.

< %@ Page Language="VB" MasterPageFile="~/Master1.master"
AutoEventWireup="true" %>
< %@ MasterType VirtualPath="~/Master1.master" %>

< script runat="server">

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
AddHandler Master.SendEmail, AddressOf EmailReport
End Sub

Protected Sub EmailReport(ByVal sender As Object, ByVal e As SendEmailEventArgs)

Dim address As String = e.ToAddress

' do work

End Sub

< /script>

Monday, January 14, 2008

Tab Control doesn't display correctly within User Control

I m using a user control in a Tab Control. I don't know why some times i get 'Sys.Res.referenceNotFound' is null or not an object javascript error.By this error my Tab control get blank.No user control is being displayed.This doesnt happen on every request.I have tried searching for the answer. but the search didn't worked. Then i finally found the answer for this problem.

The default ajax__tab_tab class has a hard-coded height of 13px.But where in my user control exceeds this height.So increasing the size of ajax__tab_tab class to 21px solved my problem.
But this may work I m not sure.But in my case it worked and got into another problem, where my other pages formatting screwed up.Then i did lot of other stuffs for that.
But make sure that other pages formatting is correct before using this fix.

Tuesday, January 8, 2008

Microsoft JScript runtime error: 'AjaxControlToolkit' is undefined

Just ran into this weird error when trying to add an AJAX control to a web page and we spent a lot of time trying to resolve this.
Basically the web page worked fine but when moving it to the server it generated a client-side JS error: "Microsoft JScript runtime error: 'AjaxControlToolkit' is undefined".

this is the corresponding code:

Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ModalPopupBehavior, {"BackgroundCssClass":"modalBackground", ...}, null, null, $get("btnNew"));
});



Google search did reveal people having similar problems but no good solution.
Then there was some good information in this thread.
Basically it turns out that the the script is being compressed under certain circumstances (like debug mode vs. non-debug) and whether the compression settings are defined in the web.config file.

Here is what fixed it for us. The important setting is the one "enableCompression='false'":

<system.web.extensions>
<scripting>
<scriptresourcehandler enablecompression="false" enablecaching="true">
</scriptresourcehandler>
</scripting>
</system.web.extensions>

Make sure you switch the compression off, since it seems it does not work, even when using IE7 like I do.

Saturday, January 5, 2008

Configuring ASP.NET AJAX

This topic describes the elements in the Web.config file that support Microsoft ASP.NET AJAX. It also describes how to incorporate those elements into the Web.config file for an existing ASP.NET application.

Using the ASP.NET AJAX Web Configuration File in a New Web Site

When you create a new AJAX-enabled Web site, you can use the Web.config file provided in the installation package to add the required configuration settings. In Visual Studio, the Web.config file for Microsoft ASP.NET AJAX is included in your project when you create a new ASP.NET AJAX-enabled Web Site.

If you have to manually add the Web.config file to a new Web site, you can get a copy of it from the installation path. By default, the file is in the following location:

drive:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.nnnn

Adding ASP.NET AJAX Configuration Elements to an Existing Web Site

In an existing Web site, you typically have values in the Web.config file that you want to retain. In that case, you can add the new ASP.NET AJAX elements into the existing Web.config file.

The new elements are part of the following configuration sections:

http://asp.net/ajax/documentation/live/ConfiguringASPNETAJAX.aspx

Friday, January 4, 2008

'Sys' is undefined - ASP.NET AJAX

You might receive the error 'Sys' is undefined when running ASP.NET AJAX Web pages or trying to AJAX enable your exisitng Web Applicaitons.

This error occurs specifically when you try upgrading your existing ASP.NET 2.0 Applications to AJAX by using the ASP.NET AJAX controls like UpdatePanel, etc., The common cause for this error is that you havent updated the Web.Config file of the application to enable the runtime understand ASP.NET AJAX. Let me explain a little more.

When you install ASP.NET AJAX your Visual Studio 2005 gets the toolbox updated with ASP.NET AJAX Server side controls like ScriptManager, ScriptManagerProxy, UpdatePanel, UpdateProgress etc., You already have your existing ASP.NET 2.0 application pages and you can add ScriptManager, UpdatePanel and other controls from Toolbox to your pages. When you run the page, you would get 'Sys' is undefined javascript error. The reason being that, your web.config of the existing ASP.NET 2.0 application misses certain settings that require to be added to make it understand the ASP.NET AJAX Server side controls like UpdatePanel, UpdateProgress etc.,

To resolve the issue, follow the steps in the link below:

http://geekswithblogs.net/ranganh/archive/2007/07/15/113963.aspx