Thursday, October 30, 2008
How to call javascript function on userControl load ?
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
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
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
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.aspxFriday, 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
How to improve ASP.NET AJAX error handling
If you’ve done much ASP.NET AJAX development, you’re no doubt familiar with JavaScript alert errors similar to the one pictured above. This particular one occurs on the official ASP.NET forums in FireFox, if you try to navigate away from viewing a user profile before the Recommended Reading panels asynchronously load.
Not only is the error message of “…” completely meaningless, but it blocks your intended navigation away from the page until you’ve dismissed the alert window. Hopefully, someone at Telligent will read this, because the ASP.NET AJAX framework gives us an easy way to replace the annoying JavaScript alerts and vastly improve the usability of our applications.
Find more details : http://encosia.com/2007/07/18/how-to-improve-aspnet-ajax-error-handling/