Asp.net modalpopupextender to implement the specified position pop-up

Source: Internet
Author: User
Overview:
Recently, Microsoft's ajaxcontroltoolkit has been used for quick development. Click "add" and a search box pops up to select "add data ".
However, because the page is long and the pop-up box is displayed in the center, it is not displayed in the middle of the screen many times. Therefore, you need to set the position of the pop-up box on the page.
Solution:
First, I tried to use document. getelementbyid (). style. top to set its vertical position, but if you have a server button in the pop-up box, such as search, Even if you put updatepanel in the pop-up box, the position of the pop-up dialog box will automatically return to the center of the entire page after the data is re-sent and loaded, probably because we only use js to set the position of the pop-up dialog box, but the server does not know, therefore, the position of the pop-up window is reset after loading.
Finally, I read the Js in the pop-up window. Code , As follows: Code
< Script Type = " Text/JavaScript " >
$ Addhandler ($
Get ( " Lnklurulesshowsearch " ), ' Click ' , Lurules_showmodalpopupviaclient );
$ Addhandler ($
Get ( " Lnklurulesreturn " ), ' Click ' , Lurules_hidemodalpopupviaclient );
Function lurules_showmodalpopupviaclient (EV ){
Ev. preventdefault ();
VaR modalpopupbehavior
= $ Find ( ' Lurules_programmaticmodalpopupbehavior ' );
Modalpopupbehavior. Show ();
}
Function lurules_hidemodalpopupviaclient (EV ){
Ev. preventdefault ();
VaR modalpopupbehavior
= $ Find ( ' Lurules_programmaticmodalpopupbehavior ' );
Modalpopupbehavior. Hide ();
}
</ Script >

We can see that the pop-up window is modalpopupbehavior. Show ();, so we can add a debugger and we can see that modalpopupbehavior has a set_y method:
Modalpopupbehavior. set_y (getelementpos ("lnklurulesshowsearch"). y );
Getelementpos is an auxiliary js method used to obtain the location of the lnklurulesshowsearch button. The final code is as follows: Code
< Script Type = " Text/JavaScript " >
// Add click handlers for buttons to show and hide modal popup on pageload
$ Addhandler ($ Get ( " Lnklurulesshowsearch " ), ' Click ' , Lurules_showmodalpopupviaclient );
$ Addhandler ($
Get ( " Lnklurulesreturn " ), ' Click ' , Lurules_hidemodalpopupviaclient );
Function lurules_showmodalpopupviaclient (EV ){
Ev. preventdefault ();
VaR modalpopupbehavior
= $ Find ( ' Lurules_programmaticmodalpopupbehavior ' );

modalpopupbehavior. set_y (getelementpos ( " lnklurulesshowsearch " ). y);

Modalpopupbehavior. Show ();
}
Function lurules_hidemodalpopupviaclient (EV ){
Ev. preventdefault ();
VaR modalpopupbehavior=$ Find ('Lurules_programmaticmodalpopupbehavior');
Modalpopupbehavior. Hide ();
}
</Script>

In this way, the pop-up window does not change the pop-up position even if the page is sent back.
Hope to help friends who encounter the same problem :)

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.