MagicAjax usage and precautions ~!!! No need to update the DLL file in AJAX !!

Source: Internet
Author: User
From: http://www.cnblogs.com/hjclove/articles/1318737.html

I. Overview
Now Ajax technology is developing on the Internet in full swing. In the face of the Web project ASP. NET1.1 we developed earlier, the interaction like the drop-down box also needs to be refreshed constantly, which indeed affects the user experience. How can we use Ajax technology to improve this part? It is a task worth thinking about and trying.
In the process of completing BMS Phase II, we used a ready-made component MagicAjax to minimize the changes to the original system and implement the attempt and system improvement of the new page without refreshing technology.
The following describes the basic process of using MagicAjax in actual projects and the issues that need attention.
2. Prepare the system for development and deployment
1. Microsoft Visual Studio. NET 2003.
2. Microsoft. NET Framework 1.1
3. Microsoft. NET Framework 1.1 HotFix (KB886903) (must be installed. Otherwise, some strange problems may occur due to incomplete viewstate)
3. Preparations for using MagicAjax
1. First of all, go to the terminal.
2. Add the dll to the reference of the project where the webForm is located.
3. Add the following subnodes under the <configuration> node in the Web. Config file:

<ConfigSections>

<Section name = "magicAjax" type = "MagicAjax. Configuration. MagicAjaxSectionHandler, MagicAjax"/>

</ConfigSections>
 

4. Add the following subnodes under the <system. Web> node in the web. Config file:

<HttpModules>

<Add name = "MagicAjaxModule" type = "MagicAjax. MagicAjaxModule, MagicAjax"/>

</HttpModules>
 

5. Introduce the Ajax registration statement at the beginning of the webForm page HTML to use Ajax:

<% @ Register TagPrefix = "ajax" Namespace = "MagicAjax. UI. Controls" Assembly = "MagicAjax" %>

In this way, we can use MagicAjax on this page.
4. Use MagicAjax
In the BMS project, I only used a MagicAjax component, that is, Ajax Panel. The usage is also very simple:
1. Package the control you need to use the refreshing operation in the MagicAjax tag, similar to the following code:

<Ajax: AjaxPanel ID = "AjaxPanel1" runat = "Server">
 
<Asp: DropDownList id = "DropDownList1" runat = "server"> </asp: DropDownList>

<Asp: DropDownList id = "DropDownList2" runat = "server"> </asp: DropDownList>

<Asp: DropDownList id = "DropDownList3" runat = "server"> </asp: DropDownList>

</Ajax: AjaxPanel>

(The code above assumes that DropDownList1, DropDownList2, and DropDownList3 have a linkage relationship, the control is set to AutoPostBack, And the linkage method has been written in the background .)
2. Go to the page and click DropDownList1. Is the previously refreshed operation unnecessary now? (Is there a loading flash in the upper left corner? This text and style can be changed ).
3. At this point, the use of MagicAjax has been basically completed, isn't it too simple. In fact, it's that simple.
V. Problems Encountered during MagicAjax usage and Solutions
In the process of using MagicAjax, you basically do not need to change the original source to achieve the effect of using Ajax technology. The implementation mechanism of MagicAjax is described on the Internet. Here we will not mention it. There are two keywords: doPostBack, and viewState. Magicajax is the operation to be performed and sent back to the backend. After processing, the required information is intercepted. In this process, doPostBack is the operation that is sent back to the background. ViewState is used to save the control status, in this way, the control status in Ajax implementation by writing xmlHttp cannot be obtained in the background (especially the option change of dropDownList.
In this process, some problems may occur due to these factors. Here we will list some of my experiences and solutions.
1. After MagicAjax is added, the page layout is messy.
In the BMS project, the page layout adopts the Table layout mode and sets the relative width of each TD. However, the page layout is messy after the AjaxPanel label is added.
Solution: After troubleshooting, it is found that a problem occurs when a statement similar to the following is included:

<Span id = "spFailcode"> <% = strFailCode %> </span>

It is easy to change the span to runnt = server and assign a value in the background.
2. Page return via click of the javascript call button is invalid.
The following client scripts may exist in the original system:

Var objQuery = document. getElementById ("btnQuery ");

If (objQuery! = Null)

{

ObjQuery. click ();

}

The page is uploaded back to the server by triggering the click Event of the button. However, after packaging the AjaxPanel, the above javascript has no effect.
Solution: magicAjax adopts doPostBack for return. So you can change Javascript to :__ doPostBack (btnQuery.
3. Call _ doPostBack to cause a script error.
This problem occurs when JavaScript is rewritten at the second point. The error type is missing. Strictly speaking, this is not caused by magicAjax applications.
Solution: Add GetPostBackEventReference (XXXX) to PageLoad. XXXX can be any server button. If the page contains a control that sets AutoPostBack, this problem does not exist.
4. The script registered on the server is invalid:
In the past, we used to write code similar to the following in future generations:

StringBuilder sbMsg = new StringBuilder ();

SbMsg. Append ("<script language = javascript> ");

SbMsg. Append ("SetFocus (" "+ Server. HtmlEncode (sid) +" ");");

SbMsg. Append ("</script> ");

Page. RegisterStartupScript ("setfocus", sbMsg. ToString ());

Currently, this method of registering scripts (including RegisterStartupScript and RegisterClientScriptBlock) is ineffective in calls triggered by MagicAjax.
Solution: first introduce the namespace: using MagicAjax on this page;
Distinguish whether a Function is called normally or MagicAjax causes a Function call. For a Function called by MagicAjax, the registration script is changed to code similar to the following:
MagicAjax. AjaxCallHelper. Write ("alert ('" + messageContent + "');");
(Remove the <script> Tag and directly Write the content through MagicAjax. AjaxCallHelper. Write)
5. Some amazing mistakes
This part of errors include: Triggering Event processing function exception, viewState loss, and so on.
Solution: Check whether Microsoft. NET Framework 1.1 HotFix (KB886903) patches are installed in the environment. Solve the problem after installation.
Vi. Conclusion
The above is a process of using MagicAjax In the BMS project and solutions to some problems. In general, MagicAjax can be used to quickly implement the MagicAjax application of asp. net1.1. It is a good way to provide Ajax solutions for existing systems. I also infer that MagicAjax is determined by the characteristics of MagicAjax (doPostBack, ViewState), and does not substantially improve the efficiency of MagicAjax. The main improvement lies in the user's sensory operations.
In addition, there are few controls that apply MagicAjax operations in this project. Some controls may have some other features in use, which is not covered in this article.
MagicAjax received great help from the Internet during the project. Thank you to those on the other side of the monitor.
Finally, if you have any experience in using MagicAjax, You can exchange and make progress together :)
Thank you.

In addition, MagicAjax has encountered some problems one after another. The following two problems are serious:
1. If the text box contains double quotation marks, the character will be escaped once it is cycled back through magicAjax.
2. in ie6, if a horizontal scroll bar appears on the MagicAjax page, the page will be extended infinitely.
 
These two problems. I have fixed it, but I want to change the Source of MagicAjax.
Alas, why is MagicAjax not updated.

Example:
1. Open vs and add MagicAjax. dll. Then there will be an AjaxPanel control. Drag it up.
2. Open web. config and add:

<ConfigSections>
<Section name = "magicAjax" type = "MagicAjax. Configuration. MagicAjaxSectionHandler, MagicAjax"/>
</ConfigSections>

<System. web>
...
<HttpModules>
<Add name = "MagicAjaxModule" type = "MagicAjax. MagicAjaxModule, MagicAjax"/>
</HttpModules>
...
</System. web>

3. Example:

Page_load:
If (! Page. IsPostBack)
{
MagicAjax. AjaxCallHelper. SetAjaxCallTimerInterval (1000 );
}
FillDataView ();

// FillDataView ();
Public void FillDataView ()
{
String SQL = "select * from mms_type ";
DataTable db = SQLControl. GetDataTable (SQL );
GridView1.DataSource = db;
GridView1.DataBind ();
}

1. How to directly bring up an Alert form: using MagicAjax; MagicAjax. AjaxCallHelper. Write ("alert ('" + "test! "+" '); "); 2. A confirmation box is displayed: (it can be used directly in MagicAjax !) This. Button2.Attributes ["onclick"] = "javascript: return confirm ('Are you sure you want to add it ');";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.