The Javascript script conflict between a custom control and a page that references the control

Source: Internet
Author: User

when creating a web system for the customer a few days ago, you need to add a "Exit System" connection to the header of each page. A confirmation dialog box is required. Generally, by adding "This. linkbutton. Attributes. Add (" onclick "," javascript: Return confirm ('Are you sure you want to exit the system? ') ")" Script. However, because there are similar prompt boxes on the home page, "htmlfile: pointer invalid" may appear in framwork1.1, And the CSS style cannot be loaded on the whole page.
here is a solution. For details, refer to the following:

1 -- The subcontrol of the custom control (related to Javascript, such as linkbutton lbnquit) can be defined as a public attribute.

2 -- add a reference to the custom space on the page that references the control, for example:

Public bankofchina. usercontorl. header header1;

The custom definition in the HTML file is as follows:

<Uc1: Header id = "header1" runat = "server"> </uc1: Header>

In this way, we define a control similar to webcontrol.



3 -- Add the following statement to the page that references the control:

Header1.lbnquit. Attributes. Add ("onclick", "javascript: Return confirm ('Are you sure you want to exit the system? ');");

4 -- The above event defines the lbnquit function to click the control to bring up the dialog box. At this time, if you "confirm the prompt", you should be able to continue

Do the following, for example:

Session. Clear (); // window. Opener = NULL;

Session ["class"] = "-1 ";

// Response. Write ("<script language = JavaScript> self. Close (); </SCRIPT>"); // This cannot be added

To enable the above execution, we can define a click event

Private void lbnquit_click (Object sender, system. eventargs E)

Summary:

After the above steps, we can implement the following process functions:

The page displays the control --> click the control --> pop-up confirmation dialog box --> confirmation prompt --> execute the defined event processing function --> end

│ Bytes

--------------- Cancel confirmation -----------------------------------



I would like to set it to public static, and then initialize the linkbutton in application_start (). However, I cannot compile the link, but I want to know how to solve it.

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.