Asp. Net2.0 pages use the ICallbackEventHandler interface to implement Ajax

Source: Internet
Author: User

1. The page inherits the ICallbackEventHandler interface.

2. Compile the server code:

 

# Region ICallbackEventHandler

String result = string. Empty;

String ICallbackEventHandler. GetCallbackResult ()
{
Return result;
}

Void ICallbackEventHandler. RaiseCallbackEvent (string eventArgument)
{
String aid = ""; // Ads id
Regex r;
Match m;

If (eventArgument. Contains ("method = getDetail "))
{
R = new Regex ("(? <= (Aid =) \ w *");
M = r. Match (eventArgument );
If (m. Success)
Aid = m. Value;
If (aid! = String. Empty)
{
Result = getaddetail (aid );
}
}
}

/// <Summary>
/// Obtain details
/// </Summary>
/// <Param name = "aid"> </param>
/// <Returns> </returns>
Private string getaddetail (string aid)
{
String r = string. empty;
Iadcolumn ad = bkservices. promotionservice. getadcolumn (aid );
If (ad! = NULL)
{
If (Ad. adcolumntype = advertisingtype. infomation_wanted)
{
Return string. Format ("{0} & {1}", ad. Name, ad. Content );
}
Else if (ad. AdColumnType = AdvertisingType. Infomation_Offering)
{
 
}
}
Return r;
}
# Endregion

 

3. Compile the client code:

 

<SCRIPT type = "text/JavaScript">

VaR docele = function ()
{
Return document. getelementbyid (arguments [0]) | false;
}

Function opennewdiv (_ id, detail)
{
// Obtain parameters
VaR items = detail. tostring (). Split ("&");
VaR M = "Mask ";
If (docele (_ id) document. Body. removechild (docele (_ id ));
If (docele (M) document. Body. removechild (docele (m ));

// Mask Mask Layer

VaR newmask = Document. createelement ("Div ");
Newmask. ID = m;
Newmask. style. Position = "absolute ";
Newmask. style. zindex = "1 ";
_ Scrollwidth = math.max(document.body.scrollwidth,document.doc umentelement. scrollwidth );
_ Scrollheight = math.max(registry.screen.availheight,document.doc umentelement. scrollheight );
Newmask. style. width = _ scrollwidth + "PX ";
Newmask. style. Height = _ scrollheight + "PX ";

Newmask. style. Top = "0px ";
Newmask. style. Left = "0px ";
Newmask. style. Background = "#999999 ";
Newmask. style. Filter = "alpha (opacity = 40 )";
Newmask. style. Opacity = "0.40 ";

Document. body. appendChild (newMask );

// New pop-up layer

Var newDiv = document. createElement ("div ");
NewDiv. id = _ id;
NewDiv. style. position = "absolute ";
NewDiv. style. zIndex = "9999 ";
NewDiv. className = "";
NewDivWidth = 562;
NewDivHeight = 260;
NewDiv. style. top = (document. body. scrollTop + document. body. clientHeight/2-newDivHeight/2) + "px ";
NewDiv. style. left = (document. body. scrollLeft + document. body. clientWidth/2-newDivWidth/2) + "px ";
Var detail = "<div class = 'pay _ lay'> NewDiv. innerHTML = detail;
Document. body. appendChild (newDiv );

// Scroll center of the pop-up layer

Function newDivCenter ()
{
NewDiv. style. top = (document. body. scrollTop + document. body. clientHeight/2-newDivHeight/2) + "px ";
NewDiv. style. left = (document. body. scrollLeft + document. body. clientWidth/2-newDivWidth/2) + "px ";
}
If (document. all)
{
Window. attachEvent ("onscroll", newDivCenter );
}
Else
{
Window. addEventListener ('scroll ', newDivCenter, false );
}

// Close the new layer and the mask Layer
NewDiv. closeMask = function ()
{
If (document. all)
{
Window. detachEvent ("onscroll", newDivCenter );
}
Else
{
Window. removeEventListener ('scroll ', newDivCenter, false );
}
Document. body. removeChild (docEle (_ id ));
Document. body. removeChild (docEle (m ));
Return false;
}
NewDiv. appendChild (newA );

}

Function closeWin ()
{
Alert ();
If (document. all)
{
Window. detachEvent ("onscroll", newDivCenter );
}
Else
{
Window. removeEventListener ('scroll ', newDivCenter, false );
}
Document. body. removeChild (docEle ('_ id '));
Document. body. removeChild (docEle ('M '));
Return false;
}

</Script>

<Script type = "text/javascript" language = "javascript">
// Ajax display details

Function getDetail (aid)
{

{

Var param = "method = getDetail & aid =" + aid;
<% = Page. ClientScript. GetCallbackEventReference (this, "param", "setDetail", "") %>;

}

}
Function setDetail (result, context)
{

OpenNewDiv ('newdiv ', result );
Return false;

}

</Script>

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.