Use the Atlas library to add the mouse drag and drop function to the web page.

Source: Internet
Author: User

I. Introduction

You can add a cool feature to your web application: This allows users to customize their own page appearances. In addition, users often prefer to reschedule the page to suit their viewing habits. Let's imagine a scenario where a user can navigate to a website, select a part of it (such as text, text, and other small pages), and dynamically move them. Today, with the help of Ajax technology such as Atlas, we can easily implement such a function.

Of course, in ASP. NET 2.0, you can also use the webparts framework to construct features similar to this pole. However, if you want to use a simpler method to add features like webparts to your page, Atlas provides you with a solution.

In this article, I will show you how to make some of your web pages "movable"; users will be able to use basic drag-and-drop mouse operations to replace all parts of the page. In particular, we can use the profile service provided by ASP. NET 2.0 to customize the page, and store the corresponding custom information for each user.

2. Build an application

Use Visual Studio 2005 to create a new Atlas application named "C: \ draganddrop ". Switch to the code-behind section of the default. aspx page.

First, set <Atlas: scriptmanager> The enablepartialrendering attribute of the control is set to "true". In this way, your page can support some page update functions: Now, since you already have an <Atlas: updatepanel> A panel control is embedded in the control. Next, you need to add some content to the control. To this end, you can add some text or another control, such as calendar, Imagemap, and so on. In this example, I want to add a clock to display the time of a selected time zone. Note that there are a lot of trendy clocks available at the site clocklink.com, so you can easily embed them into your web pages. These clocks can be updated every second on the client page without causing a page reload. Here, you will add a clock that shows the New Jersey time. To embed the clock, simply insert the following script to highlight and bold:


<Atlas: updatepanel id = "runat =" server ">
<Contenttemplate>

<Asp: Panel id = "Panel1" runat = "server" borderstyle = "solid" Height = "198px" width = "194px">

<SCRIPT rc = "http://www.clocklink.com/embed.js">

</SCRIPT>

<Strong> current time in New Zealand </strong>

<SCRIPT type = "text/JavaScript" Language = "JavaScript">

OBJ = new object;

OBJ. clockfile = "0010-red.swf ";

OBJ. timezone = "NZT ";

OBJ. width = 200;

OBJ. Height = 200;

OBJ. wmode = "Transparent ";

Showclock (OBJ );

</SCRIPT>

</ASP: Panel>

</Contenttemplate>

</Atlas: updatepanel>

At this point, you only need to press F5 to see the style of the page. Figure 1 shows how the clock is displayed in a panel control.

Figure 1. The screen snapshot shows the default. aspx page, where the clock is updated every second.

Stop running the application. Now, let's add some features to make the panel control above contain a movable clock. You will use the <Atlas: dragoverlayextender> control to achieve this purpose. In fact, the <Atlas: dragoverlayextender> Control inherits from another control and further converts it into a drag-and-drop control. Finally, you can drag and drop this control on the web page. . Now, add a <Atlas: dragoverlayextender> Control and configure it-Add a <Atlas: dragoverlayproperties> Control and set its targetcontrolid attribute to "Panel1 ". Remember to set its enabled attribute True:


<Atlas: scriptmanager id = "runat =" server "enablepartialrendering =" true "scriptmanager1? >

<Atlas: dragoverlayextender id = "dragoverlayextender1" runat = "server">

<Atlas: dragoverlayproperties targetcontrolid = "Panel1" enabled = "true"/>

</Atlas: dragoverlayextender>

Press F5 again to test the application. Now you should be able to drag the clock on the page. However, you will notice that when you release the mouse, the clock will always return to its original position. Because you cannot drag the control to other controls generated on the page and there is a blank area except the panel control on your page, this phenomenon occurs. To solve this problem, you can simply add the following attributes to the <body> element of the page:

<Body style = "font 100%;?> <Height:>

Press F5 to test the application again. Now you should be able to drag the clock and drag it to any position on the page, as long as you are still within the control range of the Panel (see figure 2 ).

Figure 2. The screen snapshot shows the same clock as Figure 1, but I dragged it to a new position with the mouse.

 


<Atlas: scriptmanager id = "runat =" server "enablepartialrendering =" true "font> <scriptmanager1?>

Next, add a <Atlas: updatepanel> Control to this page and add the <contenttemplate> element inside it. Then, add a panel control to the <contenttemplate> element and set its border style and size as follows: :

<Atlas: scriptmanager id = "runat =" server "enablepartialrendering =" true "scriptmanager1? >

<Div>

<Atlas: updatepanel id = "updatepanel1" runat = "server">

<Contenttemplate>

<Asp: Panel id = "Panel1" runat = "server" borderstyle = "solid" Height = "198px" width = "194px">

</ASP: Panel>

</Contenttemplate>

</Atlas: updatepanel>

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.