(C#) ASP.NET Web User Control & Property (Code Behind)
(C#) ASP.NET Web User Control & Property ตัวอย่างการส่งค่า Property ให้กับ Form ของ Web User Control โดยใช้ Code Behind เขียนแยกระหว่าง .aspx และ .aspx.vb หรือ .aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MyWebPage3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.MyUsrCtrl.strText1 = "www.ThaiCreate.Com 1";
this.MyUsrCtrl.strText2 = "www.ThaiCreate.Com 2";
this.MyUsrCtrl.strText3 = "www.ThaiCreate.Com 3";
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MyUserControl3 : System.Web.UI.UserControl
{
public string strText1;
public string strText2;
public string strText3;
protected void Page_Load(object sender, EventArgs e)
{
this.lblText1.Text = strText1;
this.lblText2.Text = strText2;
this.lblText3.Text = strText3;
}
}
Screenshot
ASP.NET & Visual Studio .Net 2003 - Web User Control