Dynamisk loaded user control sætte værdi
Jeg har et problem med hvordan jeg får fat i den user controls parameter fra codebehind (når jeg laver en dynamisk instans af denne) på siden.Min user control ascx fil:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestSetProject.ascx.cs" Inherits="UserControls_TestSetProject" %>
<center><h3><asp:Label ID="lblEditProjectHeadline" runat="server" Text="Projektdetaljer for"></asp:Label> <asp:Label ID="lblEditProjectNameHeadline" runat="server" Text=""></asp:Label></h3></center><br />
Min user control ascx.cs fil:
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 UserControls_TestSetProject : System.Web.UI.UserControl
{
private string _ProjectId = "";
public string ProjectId
{
get { return _ProjectId; }
set { _ProjectId = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
lblEditProjectNameHeadline.Text = ProjectId;
}
}
Min test aspx side:
<%@ Page Language="C#" MasterPageFile="~/MPHead.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Content_Test" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><asp:Label ID="lblNewProjectEditProjectId" runat="server" Text="" Visible="false"></asp:Label><br /><br /><asp:Button ID="btnPush" runat="server" Text="Push me" OnClick="btnPush_Click" /><asp:PlaceHolder ID="phNewProjectEdit" runat="server"></asp:PlaceHolder></asp:Content>
Min test aspx.cs side:
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 Content_Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Control setproject = LoadControl("~/UserControls/TestSetProject.ascx");
phNewProjectEdit.Controls.Add(setproject);
}
protected void btnPush_Click(object sender, EventArgs e)
{
lblNewProjectEditProjectId.Text = "15855";
}
}
Det jeg har brug for, er at user controllen bliver instansieret (altså oprettet) når jeg klikker på btnpush knappen på siden OG tager det jeg har skrevet ind i lblNewProjectEditProjectId.Text feltet ind i user controllens paramtere (så jeg kan bruger denne i user controllen).
Nogen der kan hjælpe mig, da jeg er på herrens mark i dette her?
mvh
simsen :-)