The Webform.aspx page accesses the methods in the WebForm.aspx.cs class through AJAX to get the data

Source: Internet
Author: User

The Webform.aspx page accesses the methods in the WebForm.aspx.cs class through AJAX to get the data

WebForm1.aspx page (native Ajax request, notation one)

<%@ page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "Ispostback.webform1"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


WebForm1.aspx page (native Ajax request, notation Two, normally we use this)



WebForm1.aspx.csIf you are using Response.End () inside the Try...catch, you will be caught with an exception: Thread aborted "Workaround: Click
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;using system.data.sqlclient;using system.data;namespace IsPostBack{public partial class WebForm1:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {string id = request["id"]; If the data is not submitted through an AJAX request, the ID is not taken, so the ID at this time is null.            However, if the data is submitted through an AJAX request, because there is a commit ID in the commit data, the ID can be taken, and the ID will have a value at that time. if (!string. IsNullOrEmpty (ID))//If the data is not submitted through an AJAX request, it will not enter the curly braces to invoke the Getuserdata (string id) method {getuserdata (ID);         If the data is submitted through an AJAX request, it enters the curly braces to invoke the Getuserdata (string id) method}} void Getuserdata (string id) {DataTable dt= sqlhelper.executedatatable ("select * from T_user where [email protected]", New SQL            Parameter ("id", id));            String Data= Datatableconvertjson.datatabletojson ("Json", DT);            Response.Write (data); RespOnse. End ();                              Send all current buffered output to the client, stop the execution of the page, and if this is not the case, the program will be executed backwards, in addition to outputting data to the client, the HTML code inside the WebForm1.aspx will be output to the page. }    }}


The Webform.aspx page accesses the methods in the WebForm.aspx.cs class through AJAX to get the data

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.