Execute controls (such as ImageButton and LinkButton) in ASP. NET without refreshing the page

Source: Internet
Author: User


Functional requirements: In the framework, use the ImageButton control to close the application and call JavaScript in The OnClick event (C #) of ImageButton to close IE.

Problem proposal: When the dialog box is displayed, the content in the subinterface is lost. Even if you do not exit the system, you cannot return to the original status.

Solution: Do not directly use the ImageButton OnClick event (C #), but use the Attributes of ImageButton. add ("OnClick", "javascript :... ") to solve this problem.

1. aspx file:
The Code is as follows:
<! -- Aspx file -->
<Asp: ImageButton ID = "ImageButton_Close" runat = "server" ImageUrl = "~ /Images/Icons/stop.gif "/>


2. C # file:
The Code is as follows:
//. Cs File
// Add events and run JavaScript code
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
ImageButton_Close.Attributes.Add ("OnClick", "javascript: if (confirm ('try it, can it be successful? ') Return false ;");
}
}


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.