Using JavaScript to trigger ASP.net server-side control events

Source: Internet
Author: User
Tags response code

When a server control has two things in one of the following ways:

1. Server-Side Click events

2. Execute AJAX request when the client clicks

The desired effect:

Execute the AJAX request first and then decide whether to execute the server response event based on the AJAX results

When a server control performs both operations at the same time, it is difficult to achieve the desired effect due to the various factors such as network speed, response rate, networking environment, or the result of the latter covering the result of the former, or the result of the former.

So, I thought of a halfway way.

First, the server control is "hidden" (note that if the server-side control is directly visiable = False, the control will become a hidden field directly, the client will not get the corresponding ID when using JavaScript to manipulate him, so it can be hidden: width = " 1px "height=" 1px "or directly using div style=" Display:none ")

Second, generate a client label next to

Third, write the corresponding Ajax event for the client tag

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

Four, when obtain the corresponding Ajax result, executes the simulation clicks the service side the Click event, specific please see the following code

Foreground code:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Test.aspx.cs" inherits= "test"%> DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

Background code:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
     
public partial class Test:System.Web.UI.Page
{
    protected void Page_Load (object sender, EventArgs e)
    {
     
    }
     
    protected void Btn_ok_click (object sender, EventArgs e)
    {
        Response.Write ("Server response Code");
    }

Author: Cnblogs A cat-eating fish

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.