1. How to configure AJAX on production server?
2. How to handle error 500?
3. How to perform an action at a specific stage of partial PostBack?
4. Why do I get PageRequestManagerParserErrorException?
5. How to register event of a control in the UserControl as the trigger of an
UpdatePanel?
6. How to register event of a control in a UserControl as the trigger of the
UpdatePanel in another UserControl?
7. How to add ScriptManager and UpdatePanel to MasterPage from ContentPage
dynamically?
8. Can HyperLink be the trigger of UpdatePanel?
9. How to trigger partial PostBack from a different window?
10. How to manipulate AJAX Timer control on client side?
11. Useful Links
1. How to configure AJAX on production server?
Here are some actions we need to perform on the production server to host an
AJAX-enabled web site on it.
A. Install AJAX Extension on the server
B. The virtual directory is configured as an application in IIS
C. The ASP.NET version of the application is configured to 2.0
D. Add some entries in web.config to register necessary assemblies,
HttpHandlers, etc. The easiest way is to create a website using the ASP.NET
AJAX-Enabled Web Site template. If you need to update an existing site, please
edit the web.config file manually. This document
(http://asp.net/AJAX/Documentation/Live/ConfiguringASPNETAJAX.aspx) explains
what is necessary and why.
2. How to handle error 500?
An error with status code 500 indicates that there is a problem when the server
tries to process the request. There can be variant causes. The problem is how to
find out the real cause of the error.
Here are two ways to find it out:
1. Set a breakpoint in the code that is responsible for processing the request,
then debug through it to find out the exception being thrown;
2. The real error message is usually returned in the response. We can use an
HTTP Sniffer (e.g., Fiddler) to peek into the traffic between the client and
server to find out the error message.
3. How to perform an action at a specific stage of partial PostBack?
In Microsoft AJAX Library, there is a client side lifecycle model similar to
the page lifecycle on server side. Developers can add different event handlers
to perform specific actions at a specific state. For example, disable a button
just before the page is going to be posted in beginRequest event handler, then
enable it again in endRequest event handler.
This document
(http://asp.net/AJAX/Documentation/Live/overview/AJAXClientEvents.aspx) contains
a full description of the order of those events, and how to use them.
Related threads:
http://forums.asp.net/t/1109705.aspx
4. Why do I get PageRequestManagerParserErrorException?
This exception may occur when we are working with UpdatePanel. Upon a partial
PostBack, the request is exactly the same as a normal PostBack’s. The
difference is that the request is sent with the XmlHttpRequest. Another notable
difference is that the response for the request is in a particular format.
Typically, the response only contains the content of the UpdatePanels to be
updated, and it must follow a specified format so that it can be parsed by the
client library to update the page.
If you try to output something additional with Response.Write, Server Trace, or
modify the output with an HttpModule, the response won’t comply with the
format any more. As a result, the client library is not able to parse it. So the
exception occurs.
In order to get rid of this, we should not use the above features when there is
an UpdatePanel on the page.
Related threads:
http://forums.asp.net/p/1140794/1844602.aspx
5. How to register event of a control in the UserControl as the trigger of an
UpdatePanel?
The best solution is to bubble up the event of the control as a custom event of
the user control. Then register the custom event of the UserControl as the
trigger of the UpdatePanel.
1. Define a custom delegate and event on the UserControl
2. Fire the custom event in the event to be bubbled up
3. Register the custom event of the UserControl as the trigger of the
UpdatePanel just like a normal control
Here is a sample:
<%@ Control Language="C#" ClassName="TestUc" %>
public delegate void ClickEventHandler(object sender, CommandEventArgs e);
public event ClickEventHandler TestCustomEvent; protected void lb_Command(object
sender, CommandEventArgs e) { // bubble up the command event as TestCustomEvent
if (TestCustomEvent != null) TestCustomEvent(this, e); } LinkButton1 LinkButton2
<%@ Page Language="C#" %> <%@ Register
src="TestUc.ascx" TagName="TestUc" TagPrefix="uc1"
%> protected void TestUc1_TestCustomEvent(object sender, CommandEventArgs e)
{ Label1.Text = DateTime.Now.ToString(); } Untitled Page
Related threads:
http://forums.asp.net/t/1138191.aspx
http://forums.asp.net/t/1123812.aspx
http://forums.asp.net/t/1141328.aspx
http://forums.asp.net/t/1175921.aspx
6. How to register event of a control in a UserControl as the trigger of the
UpdatePanel in another UserControl?
In order to do that, we can first define a custom property to expose the client
ID of a hidden trigger control of the UpdatePanel on the UserControl (say
“UserControlA”). On the other UserControl (say “UserControlB”), we will
be able to fire the click event of the hidden trigger control.
Here are the specific steps:
1. Define a custom property to store the client ID of a hidden trigger control
of the Update Panel(Button1clientID property of Gallery User Control):
<%@ Control Language="C#" ClassName="Gallery" %>
protected void Button1_Click(object sender, EventArgs e) { Label1.Text =
DateTime.Now.ToString(); } public string Button1clientID { get { return
Button1.ClientID; } }
2. Define a custom property in the other User Control(Button1clientID property
of Upload User Control):
<%@ Control Language="C#" ClassName="Upload" %>
private string buttonclientID = ""; public string Button1clientID {
set { buttonclientID = value; } }
3. Set Upload1.Button1clientID = Gallery1.Button1clientID in the page_Load:
protected void Page_Load(object sender, EventArgs e) { Upload1.Button1clientID
= Gallery1.Button1clientID; }
4. Fire the click event of the hidden trigger control manually:
function submitForm() { document.getElementById("").click(); } Upload
Here is the full sample code:
http://forums.asp.net/p/1117746/1739422.aspx#1739422
Related threads:
http://forums.asp.net/t/1117746.aspx
http://forums.asp.net/t/1136932.aspx
7. How to add ScriptManager and UpdatePanel to MasterPage from ContentPage
dynamically?
The ScriptManager must be added before the initialization stage of a page that
requires it. Otherwise, an InvalidOperationException will be thrown (it
complains about the lack of ScriptManager on the page). It’s better to add it
in Page_PreInit which fires before initialization.
For example:
protected void Page_PreInit(object sender, EventArgs e) { HtmlForm form1 =
(HtmlForm)Master.FindControl("form1"); ScriptManager sm = new
ScriptManager(); sm.ID = "ScriptManager1"; form1.Controls.AddAt(0,
sm); // add a UpdatePanel and moves an existing control into it UpdatePanel
panel = new UpdatePanel(); panel.ID = "upMaster"; Control ctrl =
((Control)Master.FindControl("TextBox1"));
panel.ContentTemplateContainer.Controls.Add(uc); form1.Controls.Add(panel); }
Related threads:
http://forums.asp.net/t/1165939.aspx
http://forums.asp.net/t/1160425.aspx
http://forums.asp.net/t/1163971.aspx
8. Can HyperLink be the trigger of UpdatePanel?
No. Please refer to this document:
http://www.asp.net/AJAX/documentation/live/mref/P_System_Web_UI_UpdatePanelContr
olTrigger_ControlID.aspx. The trigger must implement the INamingContainer,
IPostBackDataHandler, or IPostBackEventHandler interface. HyperLink doesn’t
implement any of them.
Also See:
1. INamingContainer 2. IPostBackDataHandler 3. IPostBackEventHandler Related
threads:
http://forums.asp.net/t/1138804.aspx
http://forums.asp.net/t/1099204.aspx
http://forums.asp.net/t/1170105.aspx
9. How to trigger partial PostBack from a different window?
There are cases when we need to trigger partial PostBack from a different
window. For example: trigger partial PostBack in parent window from IFrame,
trigger partial PostBack in opener from a popup window.
We can add an invisible button (say Button1) on pageA, and set it to be the
trigger of the UpdatePanel, and then we need to get a reference to this button
from pageB and fire click on it to trigger a partial PostBack. It’s achievable
with the following javascript.
"window.parent.document.getElementById('Button1').click()”
“window.opener.document.getElementById('Button1').click()"
Here is the full sample code:
http://forums.asp.net/p/1162285/1927000.aspx#1927000
Related threads:
http://forums.asp.net/t/1162285.aspx
http://forums.asp.net/t/1117770.aspx
http://forums.asp.net/t/1169365.aspx
10. How to manipulate AJAX Timer control on client side?
To manage the Timer control on client side, we need to get a reference to the
client side component with $find method like this:
var timer = $find("Timer1");
Then, we can call set_interval method to set the interval of the Timer control,
_stopTimer method to stop it and _startTimer method to start it.
Here is a sample:
function setTimer() { var timer = $find("Timer1");
timer.set_interval(100); } function startTimer() { var timer =
$find("Timer1"); timer._startTimer(); } function stopTimer() { var
timer = $find("Timer1"); timer._stopTimer(); }
Related Threads:
http://forums.asp.net/t/1159648.aspx
http://forums.asp.net/t/1163431.aspx
11. Useful Links
Official website of AJAX Extension
http://www.asp.net/AJAX/
Documents about AJAX Extension
http://www.asp.net/AJAX/documentation/
Video tutorials for AJAX
http://www.asp.net/learn/AJAX-videos/
AJAX Control Toolkit Project Page
http://www.codeplex.com/Wiki/View.aspx?ProjectName=AtlasControlToolkit
AJAX Control Toolkit online sample
http://www.asp.net/AJAX/AJAXcontroltoolkit/samples/
How to play an Animation?
http://blogs.msdn.com/phaniraj/archive/2007/04/13/animations-how-many-ways-do-i
-call-thee.aspx
How to: Re-use Animation Extenders in a page
http://blogs.msdn.com/phaniraj/archive/2007/08/15/how-to-re-use-animation-exten
ders-in-a-page.aspx
How to: Perform Operations on all instances of a AJAX Control Extender on a
page
http://blogs.msdn.com/phaniraj/archive/2007/08/15/how-to-re-use-animation-exten
ders-in-a-page.aspx
How to: Use a Key Value Pair in your AutoCompleteExtender
http://blogs.msdn.com/phaniraj/archive/2007/06/19/how-to-use-a-key-value-pair-i
n-your-autocompleteextender.aspx
Scripting Animations from the Ms AJAX AnimationExtender
http://blogs.msdn.com/phaniraj/archive/2007/05/31/scripting-animations-from-the
-ms-AJAX-animationextender.aspx
HowTo : Change Visible Tab Using JavaScript in the MS AJAX TabControl
http://blogs.msdn.com/phaniraj/archive/2007/04/16/howto-change-visible-tab-usin
g-javascript-in-the-ms-AJAX-tabcontrol.aspx
Show and Hide ModalPopupExtender from JavaScript
http://blogs.msdn.com/phaniraj/archive/2007/02/20/show-and-hide-modalpopupexten
der-from-javascript.aspx
Change ServiceMethods and Web Service for the AutoCompleteExtender From Client
Side
http://blogs.msdn.com/phaniraj/archive/2007/02/16/change-servicemethods-and-web
-service-for-the-autocompleteextender-from-client-side.aspx
|