Asp. NET pop-up window technology

Source: Internet
Author: User
Tags closing tag

To improve the concurrency and throughput of web site access, as with other server scripts, ASP. NET also uses client-side scripting to mitigate server pressure. Asp. NET does not directly support pop-up windows until now (version 1.1), and you must use the Client pop-up window through JavaScript (or VBScript).

One, warning windows and how to use client script in Codebehind

To eject one of the simplest warning windows in the browser, you can use JavaScript statements:

Window.alert ([smessage])

Among them, smessage is the hint information. Unfortunately, this pop-up window is only a "OK" button, can only play a role in prompting. If we want to pop up an inquiry pop-up window when we delete the record, you need to use:

bconfirmed = Window.confirm ([smessage])

Where: Bconfirmed is the return value, smessage is the hint information. This pop-up window has two options: OK or abort, and the return value of the selection is placed in the bconfirmed for the code to judge.

In order to improve the reusability and readability of the code, JavaScript and codehind should be fused to each other. There are usually two ways to achieve this effect.

(1) using the Response.Write method:

The use of the Response.Write method has been supported as early as in the ASP era. It can write code to the client, is a very convenient and intuitive way. The following code demonstrates how to use the Response.Write method to display a warning message.

Private Sub Btalert_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Btalert.click

' Demo Response.Write method and Alert window.

Response.Write ("")

End Sub

(2) Using Registerxxx method

If you look at Response.Write generated HTML code, you will find that the code generated by the Response.Write method is written to the beginning of the HTML code, that is, before the tag. At this point, all of the HTML objects have not been generated, and if you want to use the objects within HTML and interact with them, there will be an "object not found" error. Therefore, the author recommends a more consistent codebehind way----use registerxxx method. Registerxxx include: RegisterClientScriptBlock, RegisterStartupScript, and isstartupscriptregistered functions for judgment.

RegisterStartupScript's prototype is:

Overridable Public Sub RegisterStartupScript (_

ByVal Key as String, _

ByVal Script as String _

)

Where: Key represents the unique identifier of the script, which is a string representing the script.

The RegisterClientScriptBlock prototype is the same as RegisterStartupScript, and two functions differ in that the scripting code it contains is written to a different location in the HTML file. RegisterClientScriptBlock the client script immediately after the start tag of the element of the Page object, RegisterStartupScript emits the script before the closing tag of the element of the Page object. If your script has a statement that interacts with a Page object (which is seen in the example that follows), it is recommended to use RegisterStartupScript, whereas if you want the client script to execute as early as possible, You can use RegisterClientScriptBlock or Response.Write.

To prevent repeated scripting in the page, Reisterstartupscript/registerclientscriptblock uses key as the registered key when registering the script. Then you can use isclientscriptblockregistered to make judgments in your program.

The following example uses RegisterClientScriptBlock to demonstrate how confirm is used.

Private Sub Btconfirm_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Btconfirm.click

Demo RegisterClientScriptBlock methods and confirm windows

If (Not isclientscriptblockregistered ("ClientScript")) Then

' To determine if the script has been added or not to join.

Dim Strscript as String

Strscript = ""

' Register script

RegisterClientScriptBlock ("ClientScript", Strscript)

' If you choose ' No ', continue down execution.

End If

End Sub
  
second, pop-up specified page

The hint window is still far from satisfying our requirements, in the program, we often need to pop the specified page. You can use the Window.Open method of JavaScript at this point. With the previous Registerclientsciptblock method, we can implement the pop-up of the specified page.

The following code shows how to eject the specified page:

Private Sub Btwinopen_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Btwinopen.click

' Use window.open and RegisterStartupScript for a simple demo.

If (Not isclientscriptblockregistered ("Openscript")) Then

' To determine if the script has been added or not to join.

Dim strscript as String = ""

RegisterStartupScript ("Openscript", Strscript)

End If

End Sub

The program uses the Window.Open method to pop up a new page with only one parameter: the URL address of the new pop-up window. The fact that there are multiple parameters in the Window.Open method, but this is javascipt simple content, we will not be here in detail locutionary. If you have related questions, please check MSDN.

This program is used directly in IE with all normal. But if you're using a browser like Gosurf, MyIE2, and Netcapter, it's unfortunate! You will not see the pop-up window. That's what we're going to talk about. Popup filter problem.

Third, non-standard IE browser to pop-up window filter behavior discussion

The proliferation of advertising windows has caused many Internet users to give up the advertising harassment of the standard IE browser and the use of such as Gosurf, MyIE2, netcapter such as the use of IE kernel to support multiple pages and can automatically screen ads software. It is said that Microsoft will also join the ban on advertising windows in the upcoming IE6 SP2. This is of course a good thing for most netizens, but for programmers, the way we use pop-up windows is not the same as the normal ads, such windows will be blocked by the pop-up window manager indiscriminately, the result of course is we do not want to see. Is there a standard way to get the window to pop up normally? This requires us to understand the browser blocked advertising principle. The usual ad-blocking device uses the following three ways to filter ads:

(1), based on the window title of the blocking method

The principle of this method of blocking is to check all the IE window titles regularly, and then compare the existing list (a list of arrays maintained by the program), and if there is one, we close the window. Obviously, this way has a lot of flaws, it blocked all the pop-up window, tube too dead, in the program really use very little. However, it is quite common to use it in terms of deformation. That is, based on the window title of the intelligent filtering technology, it is based on pop-up window title contains ads on the keyword to block, which to improve the effectiveness of the filter to make a good exploration.

(2), based on the window class and location of the blocking method

After analysis found that the normal browsing window's class name is Ieframe and Cabinetwclass, and the Advertisement window class name is Cabinetwclass. Further analysis found that the Workera class of the advertising window and the value of the rect.top of the Shell DocObject view class are the same, and that the Workera class of the normal IE window and the DocObject value of the shell Rect.top view class are different. Based on the above two points can be written ads killer program. In fact, I am skeptical of the generality of this procedure. Because the author uses Spy + + analysis discovers, in Windows2000 (the author uses the operating system), the IE window class all is ieframe. At the same time, because Win2000 is an operating system based on Unicode code, there is no Workera class, instead of a workerw class. At the same time, there is no rect.top, because the author does not have Windows XP operating system, so can not be further test for Windows XP.

(3), based on IE COM components of the blocking method

Both of the above methods are to treat the IE window as a common Windows window, to judge. In fact, IE is a typical COM component based browser, all the browser based on IE kernel is the wrapper Shdocvw.dll file, and then write the corresponding BHO code. Only in this way can the real control of IE browser, rather than method one or two such nowhere near.

There is also a pop-up window blocking method based on IE kernel. It can be intercepted before the pop-up window is opened. The principle is: whenever IE open a new window will trigger the NewWindow event, the implementation of ONNEWWINDOW2 ([out] idispatch*, [out] BOOL *bcancel) method. Overload this method to determine whether opening a new window event occurs after the browsing page has been downloaded. If yes, the description is a normal pop-up window, otherwise it is intercepted.

Because browsers such as Gosurf themselves overload the Shocvm.dll component, using a third method naturally becomes a logical thing. However, in the use of the process is sometimes found that the advertising filter is not perfect, but the principle is basically so

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.