In this demo, the interface (interface) is used to dynamically load the user control on the Web page, and jquery is used to pass the values processed by the Web page to the user control.
In programming, it is preferred to use an interface that can handle the same behavior for different objects.
Copy Code code 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 a control after it has been implemented.
Next, we create a user control, where the user control's ascx places a label label that will be used to display the values passed from the page. In a real environment, it may not be a simple label control, but another control, or an object.
Copy Code code as follows:
<%@ control language= "C #" autoeventwireup= "true" codefile= "InsusUc.ascx.cs" inherits= "Insusuc"%>
<asp:label id= "labelmessage" runat= "Server" text= "" ></asp:Label>
Within the Ascx.cs code, the interface needs to be implemented to assign the parameters of the method implemented by the interface to the label's text.
Copy Code code 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 is created with the user control and you need to create a Web page. Write a Web methods method in. aspx.cs:
. aspx:
Animation Demo: