Create a way to create a pop-up window in .NET

zhaozj2021-02-16  49

Create a pop-up method in .NET

I have seen a lot of .Net developers often use pop-up windows, about how to create a pop-up window in .NET, usually a problem that is easy to arousely discuss in some forums, but the solution is alive: in HTML ( .ASASPX) The client is embedded in the client, but many people will ask: How should I create a pop-up window in the back code file using the Code Behind technology instead of the html (.aspx) file? Now, some developers are hesitant to implement whether to use JavaScript to embed the ASP.NET page, but I strongly recommend not embed any scripts such as JavaScript, such as <% =%> and other tags into the ASP.NET page. It is obvious that these are what we should avoid, because we all know in .NET, in most cases, we all completed all event logic in the back code file of Code Behind. Of course, most .NET developers like the event logic code for creating a page at the back code file of Code Behind. In this article, we will establish an overload function to facilitate our creation of pop-up windows in what you need. Behind this article, we will also demonstrate how to create a pop-up window with a calendar control (translation: due to the main article Talk about how to create a pop-up window, about how to create a page with a calendar control, please refer to John Kilgo article: CREATE A Popup Calendar for ASP.NET Web Forms). Let us now take a look at how to implement it if you can call a function when you need to create a pop-up window, it will be a good thing: OpenPopup (ControlToClick, PageToopen)) Parameters ControlToClick Can be the ID of any ASP.NET Web control, the parameter pageToopen is the page you want to use in the pop-up window, as follows is the function code to implement this feature: public shared sub openpopup (Byval Opener as system.web.ui.webcontrols. WebControl, Byval PagePath AS String) Dim Clientscript as string

'Building the client script- window.open clientScript = "window.open ('" & PagePath & " ')"' register the script to the clientside click event of the opener control opener.Attributes.Add ( "onClick", clientScript) End Sub But don't think you call this method to open the pop-up window. Accordingly, we need to configure a startup control as a client calling the function, which can be any ASP that supports the browser-only click event. NET web control. Please see the following code: OpenPopup (Button1, "http://www.google.com") This code configures Button1 to start the control, that is, when we click Button1, connect to the window connected to Gole.com. In order to make this function more versatility, we use the overloaded method to create a function of the same name and the parameters, using this function you will set the name, width, and height of the pop-up window (the unit is pixel), and the window will also appear in the center of the display: Public Shared Sub OpenPopUp (ByVal opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String, ByVal windowName As String, ByVal width As Integer, ByVal height As Integer) Dim clientScript As String Dim windowAttribs As String'Building Client side window attributes with width and height. 'Also the the window will be positioned to the middle of the screen windowAttribs = "width =" & width & "px," & _ "height =" & Height & "PX," & _ "Left = ' (Screen.Width -" & Width & ") / 2) '," & _ "TOP = ' (Screen.Height -" & Height & ") / 2 '"

'Building The Client Script - Window.open, With Additional Parameters Clientscript = "WINDOW.OPEN ('" & windowPath & ", '" & windowAme ",'" & windowattribs & "); return false;" ' Register the script to the clientside click Event of 'Opener' Control Opener.attributes.add ("onclick", clientscript) End ("OnClick", Clientscript) End Sub is here compared with the previous functions, we did not create what new things in which Opener.attribute.Add ( "Onclick", clientscript means the same in two functions: register a script on the client to create a clicking corresponding event. Now you can continue to use the rapid development of applications from Code Behind technology, you can make any changes in Visual Studio, you can make debugging and running programs, and avoiding html (.aspx) pages. The code brought by the JavaScript script is scattered.

转载请注明原文地址:https://www.9cbs.com/read-22897.html

New Post(0)