Monday, July 26, 2010

Versed in pop-up window for ASP.NET



As Microsoft's latest tools to create dynamic Web sites, ASP.NET compared to ASP and JSP Web Programming in changing the way the original had made great strides grow. Its code and page separation technology (CodeBehind) and a good Web server control for the programmer to provide a more in keeping with the traditional server-side Web programming development methods. However, traditional Web programming or programming with different characteristics, which determine the ASP.NET programming must be some special skills to complete the program requirements, pop-up window is representative of the way of such programming. A lot of programming books on the pop-up window with the words to silent or off, seems to see the great use of pop-up window, but heaven and earth. This will pop-up window, you unlock most of the problems in use.

In order to improve site access concurrency and throughput, as with other server script, ASP.NET also uses a client-side script to ease server stress. ASP.NET now (version 1.1) does not directly support the pop-up windows, must javascript (or VBScript) to use client-side pop-up window.

First, a warning window and in the CodeBehind in a way using client script

In the browser to pop up a simple warning window, you can use the javascript statement:

window.alert ([sMessage])

Which, sMessage is message. Unfortunately, such a pop-up window is only an "OK" button, and can only play a role in tips. If we want to delete the record when asked about the pop-up a pop-up window, then you need to use:

bConfirmed = window.confirm ([sMessage])

Where: bConfirmed is the return value, sMessage is message. The pop-up window there are two options: "OK" or "abandoned", the return value of their choice on the bConfirmed, the available code to make judgments.

In order to improve code reusability and readability, should enable javascript and Codehind fused with each other. There are usually two ways to achieve such results.

(1) use Response.Write method:

Use the ASP Response.Write method early era have been supported. It can write client code 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

'Response.Write method and the alert window shows.

Response.Write ("")

End Sub

(2) the use of RegisterXXX method

If you look at the generated HTML code Response.Write, you will find Response.Write method to generate the code is written to the beginning of the HTML code that tag. At this point, all the HTML objects are not generated, if it is to use the HTML within the object, and interact with, there will be "object not found" error. Therefore, I recommend a more consistent way ---- CodeBehind way to use RegisterXXX method. RegisterXXX include: RegisterClientScriptBlock, RegisterStartupScript and used to determine the IsStartupScriptRegistered function.

RegisterStartupScript prototype is:

Overridable Public Sub RegisterStartupScript (_

ByVal key As String, _

ByVal script As String _

)

Including: key that uniquely identifies the script, script string representing the script.

Prototype and RegisterStartupScript RegisterClientScriptBlock the same two functions is to contain different script code is written to the HTML file a different location. RegisterClientScriptBlock elements in the Page object issued immediately after the opening tag of client-side script, RegisterStartupScript is the element in the Page object tag issued before the end of the script. If your scripts have the page object (doucument objects) to interact with the statement (which we later see examples), the recommended RegisterStartupScript, otherwise if it is to client-side script execution as early as possible, you can use RegisterClientScriptBlock or Response.Write.

In order to prevent repeated by adding the script in the page in the registration script ReisterStartupScript / RegisterClientScriptBlock registered to use the key as the Key, then the program can be used to judge IsClientScriptBlockRegistered.

The following example will demonstrate the use RegisterClientScriptBlock to confirm the use.

Private Sub btConfirm_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btConfirm.Click

'Presentation method and confirm the window RegisterClientScriptBlock

If (Not IsClientScriptBlockRegistered ("clientScript")) Then

'Determine whether the script has been added, not the join.

Dim strScript As String

strScript = ""

'Register script

RegisterClientScriptBlock ("clientScript", strScript)

'If you select "No", then continues.





1, pop-up page specified

Light a prompt window is still far from meeting our requirements, in the process, we often need to specify the pop-up page. At this point you can use javascript's window.open method. With the previous RegisterClientSciptBlock way, we can achieve the specified pop-up page.

The following code shows how to specify the pop-up page:

Private Sub btWinOpen_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btWinOpen.Click

'Using window.open and registerStartupScript simple demonstration.

If (Not IsClientScriptBlockRegistered ("OpenScript")) Then

'Determine whether the script has been added, not the join.

Dim strScript As String = ""

RegisterStartupScript ("OpenScript", strScript)

End If

End Sub

Uses Window.open way to pop a new page, only one parameter: the new pop-up window URL address. The fact that there are more parameters in window.open method, but this is javascipt simple, and we will not be detailed here Annotated. If you have a related issue, please consult MSDN.

This procedure be used directly in IE everything is normal. But if you are using the class as GoSurf, MyIE2, NetCapter like the browser, then, unfortunately! You will not see the pop-up window. This is what we will be discussing the issue pop-up filter.

Second, non-standard IE browser pop-up discussion of the filtration behavior

The overflowing window advertising unbearable overwhelming number of Internet users have to give up the standard of advertising harassment to use IE browser, such as GoSurf, MyIE2, NetCapter this page using the IE core and multi-screen advertising the software automatically. It is said that the upcoming release of IE6 sp2 in the Microsoft ad window to join the block function. This is a good thing that most Internet users, of course, be for the programmer, the way we use pop-ups and general advertising is not essentially different, so the window will be pop-up window manager indiscriminate white block, the results of course, we do not want to see. Is there a standard way to make a normal pop-up window then? This requires that we understand the browser to block ads principle. Typically uses ad blocking ads filtering the following three ways:

(1), based on window title block approach

In the reference [1] presents a window title filtering based on block means. Its principle is to regularly check all of the IE window title, and then have some on list (maintained by the program, an array list) to compare, if the same, we will close this window. Obviously, this approach has many defects, it blocked all the pop-up windows, tightly managed, very few actually use the program. However, according to the deformation it down fairly common use. That is, based on the window title name of the smart filter technology, which is under the title of pop-up window containing the keywords on the ad ban, which has made to improve the filtering effect of the exploration well.

(2), based on window type and location of block mode

Reference [2] presents a window class and location-based blocking mode. Its analysis of the normal browser window class name is IEFRAME and CabinetWClass, and ad window class name is CabinetWClass. Further analysis found that: ad window WorkerA classes and Shell DocObject View class rect.top values are the same, normal IE window WorkerA classes and Shell DocObject View class rect.top values are not the same. Based on the above two procedures can write a killer ad.

In fact, I have the program universal skepticism. Because I used Spy + + analysis found that in Windows2000 (I use the operating system) in, IE window class for the IEFrame. Also, because Win2000 is a Unicode based operating system code, so there is no WorkerA class, and to WorkerW class instead. At the same time, there was no rect.top not the same situation, because I did not WindowsXP operating system, it can not be further tests for WindowsXP.

(3), based on IE COM component block approach

These two methods are the IE window as a normal Windows window treatment, to judge. In fact, IE is a typical browser-based COM components, all browser based on IE core files are packaged shdocvw.dll, and then writing a corresponding BHO code. The only way to achieve real control of IE browser, not the method of one or two such and inadequate.

Reference [3] presents a pop-up based on IE kernel block method. It can block pop-ups before they open. The principle is: when IE opens a new window will be triggered when NewWindow event, the Executive OnNewWindow2 ([out] IDispatch *, [out] BOOL * bCancel) method. Override this method to determine whether to open a new window incident occurred in the view after the page has been downloaded. If so, that is, a normal pop-up window, contrary to intercept.

Browser such as Gosurf override Shocvm.dll component itself, so use the third method, it naturally became a matter of course. However, sometimes in the course of discovery, ad filter is not perfect, but the basic principle of the case.







Recommended links:



Easy Audio CD Players



Do not let the knowledge base has become Garbage



Catalogs Newsgroup Clients



Liu Xu Micro point: there will be more soon to be opened Insider



Considerate: Foxmail 6.0 beta 3 the beginning of experience



converting mov to wmv



Forbes: Goodbye, Alibaba?



comments Text Or Document Editors



Chinese input method commonly used fast switching



avi to mp4 Converter



AJAX Push and Pull methods comparison



.MKV file



Workplace COMPETITIVENESS "soft skills"



flv to SWF



What is most needed boss



1 comment:

  1. It can also diagnose your check out engine gentle. This can then effortlessly turn out an erroneous code appears on
    your dashboard.

    My web site ... obd 2007

    ReplyDelete