JQuery assigns values to user controls (ASCX) and applications to interfaces

Source: Internet
Author: User

In this demonstration, an interface is used to dynamically load the user control on the webpage, and JQuery is used to pass the webpage processing value to the user control.

In programming, I prefer to use interfaces and think they can process the same behavior between different objects.
Copy codeThe Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;

/// <Summary>
/// Summary description for ISetValable
/// </Summary>
Namespace Insus. NET
{
Public interface ISetValable
{
Void SetValue (string value );
}
}

The above interface is to assign a value to the control after the object is implemented.

Next, we create a user control. The ascx of the user control places a Label to display the value passed from the page. In the real environment, it may not be a simple Label control, but other controls or objects.
Copy codeThe Code is as follows:
<% @ Control Language = "C #" AutoEventWireup = "true" CodeFile = "InsusUc. ascx. cs" Inherits = "InsusUc" %>
<Asp: Label ID = "LabelMessage" runat = "server" Text = ""> </asp: Label>

In the ascx. cs code, you need to implement the interface and assign the parameters of the method implemented by the interface to the Text of the Label.
Copy codeThe Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using Insus. NET;

Public partial class InsusUc: System. Web. UI. UserControl, ISetValable
{
Protected void Page_Load (object sender, EventArgs e)
{

}
Public void SetValue (string value)
{
This. LabelMessage. Text = value;
}
}

OK. The interface and user control have been created. You need to create a webpage. Write a web method in. aspx. cs:

. Aspx:

Animation demonstration:

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.