Saturday, March 24, 2012

Pass values to .ascx

Hi,

Simple question really, how do i pass values to a .ascx file from .aspx file in c#?

ThanksYou can set property values from your ASPX code.

This site has ALL in the info you'll need, I just found it myself the other day.

Mastering Page-UserControl Communication
I tried this once with a page with a tabstrip + multipage setup. Each tab contained it's own ascx file.

I never got it to work the way I thought that it should. Check this newsgroup thread of mine to see if it applies to you:

http://msdn.microsoft.com/newsgroups/default.aspx?pg=35&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.dotnet.framework.aspnet.webcontrols&fltr=
I came accross the following code that solved my problem, might help others also.


in myuc.aspx
----------
<%-- declare any namespaces --%>
<%@. Register Tagprefix="Channel" Tagname="Title" src="http://pics.10026.com/?src=myuc.ascx"%>
<Channel:Title MyTitle="ABC" /
In myuc.ascx
----------
<script language="C#" runat="server">
public String MyTitle ="Not Set";
void Page_Load(Object Sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
DisplayTitle.Text = MyTitle.ToString();
}
}
</Script>
<asp:Label id="DisplayTitle" runat="server" />

Check out the MSDN article by Scott Mitchell: An extensive Examination of User Controls

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/usercontrols.asp
Hello, you might check :An Extensive Examination of UserControls

regards

0 comments:

Post a Comment