Un po'di codice...
Pagina aspx
codice:
<%@ Register TagPrefix="uc1" TagName="WUC1" Src="WUC1.ascx" %>
<%@ Page language="c#" Codebehind="TestWUC.aspx.cs" AutoEventWireup="false" Inherits="TestVariCSharp.TestWUC" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>testWUC</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT id="Hidden1" style="Z-INDEX: 101; LEFT: 360px; POSITION: absolute; TOP: 256px" type="hidden"
name="Hidden1" runat="server" value="pippo">
<uc1:WUC1 id="WUC11" runat="server"></uc1:WUC1>
</form>
</body>
</HTML>
Pagina aspx.cs
codice:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TestVariCSharp
{
/// <summary>
/// Summary description for TestWUC.
/// </summary>
public class TestWUC : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1;
protected TestVariCSharp.WUC1 WUC11;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
WUC11.url = "testetets";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
UserControl ascx
codice:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="WUC1.ascx.cs" Inherits="TestVariCSharp.WUC1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:Label id="Label1" runat="server">Label</asp:Label>
<asp:Label id="Label2" runat="server">Label</asp:Label>
UserControl ascx.cs
codice:
namespace TestVariCSharp
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for WUC1.
/// </summary>
public class WUC1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
private string _url;
public string url{get{return _url;} set {_url = value;}}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
HtmlInputHidden h;
h = (HtmlInputHidden)Parent.FindControl("Hidden1");
this.Label1.Text = h.Value;
this.Label2.Text = this.url;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
Ci sono dentro tutti e duei metodi
Fammi sapere
Ciao
K