Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JQuery to assign a value to a user control ASCX

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to use JQuery to assign values to user controls ASCX, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

In this demo, we use the interface to dynamically load user controls on web pages, and use JQuery to pass values processed by web pages to user controls.

In object-oriented programming, interfaces are preferred because they are thought to handle the same behavior for different objects.

The copy code is as follows:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

///

/// Summary description for ISetValable

///

namespace Insus.NET

{

public interface ISetValable

{

void SetValue(string value);

}

}

The above interface is intended to allow objects to be implemented and assigned values to controls.

Next, we create a user control whose ascx places a Label label that will be used to display the values passed from the page. In the real environment, it may not be a simple Label control, but other controls, or objects.

The copy code is as follows:

In the ascx.cs code, you need to implement the interface, and assign the parameters of the method implemented by the interface to Text.

The copy 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 controls are created, and the web page needs to be created. Write a web method in.aspx.cs:

.aspx:

Animation demo:

About "how to use JQuery for user control ASCX assignment" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report