470,594 Members | 1,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

User Control doubt:

Hello all,

I have in my project this user control I made:
public class PollControl : System.Web.UI.UserControl

I have properties on its code-behind like:

****************************
private string _name;
private ArrayList _choices;

public string Name
{
get {return _name;}
set {_name=value;}
}
public ArrayList Choices
{
get {return _choices;}
set {_choices=value;}
}
**********************

I added the control to a webform:
<%@ Register TagPrefix="CustCtrl" TagName="Poll" Src="Poll.ascx" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="Poll.WebForm1" %>

<form id="Form1" method="post" runat="server">
<CustCtrl:Poll id="id1" runat="server"
Name="ProgrammingPoll"></CustCtrl:Poll>
</form>

As shown, I can assigne a value to the Name property by specifying a value
in the Name attribute in the HTML. But what if I want to programmatically
pass an ArrayList to the Choices property from the webform's code-behind?

How can I get a reference at the codebehind to the Poll control I added on
the web form HTML interface, so that I can do:

id1.Choices= arrayListXYZ;

Thanks in advance
CSharp
Nov 18 '05 #1
2 1039
u need to load the control dynamically in the code behind and add it to page
collection.

UControl myControl = Page.LoadControl("~/UControl.ascx");

to place it in a proper position, add a panel in design mode and add your
control to the panel.

Av.
"CSharp" <sm****@asianetindia.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
Hello all,

I have in my project this user control I made:
public class PollControl : System.Web.UI.UserControl

I have properties on its code-behind like:

****************************
private string _name;
private ArrayList _choices;

public string Name
{
get {return _name;}
set {_name=value;}
}
public ArrayList Choices
{
get {return _choices;}
set {_choices=value;}
}
**********************

I added the control to a webform:
<%@ Register TagPrefix="CustCtrl" TagName="Poll" Src="Poll.ascx" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="Poll.WebForm1" %>

<form id="Form1" method="post" runat="server">
<CustCtrl:Poll id="id1" runat="server"
Name="ProgrammingPoll"></CustCtrl:Poll>
</form>

As shown, I can assigne a value to the Name property by specifying a value
in the Name attribute in the HTML. But what if I want to programmatically
pass an ArrayList to the Choices property from the webform's code-behind?

How can I get a reference at the codebehind to the Poll control I added on
the web form HTML interface, so that I can do:

id1.Choices= arrayListXYZ;

Thanks in advance
CSharp

Nov 18 '05 #2
Thanks for the solution.
I found out that it also works like this though:

I can add the control, to the webform html as I said.
In the code behind, I add this declaraion:
protected Poll.PollControl id1;

And now I can access the control in the code behind too.

Thanks anyway
CSharp


"avnrao" <av*@newsgroups.com> wrote in message
news:#S**************@TK2MSFTNGP10.phx.gbl...
u need to load the control dynamically in the code behind and add it to page collection.

UControl myControl = Page.LoadControl("~/UControl.ascx");

to place it in a proper position, add a panel in design mode and add your
control to the panel.

Av.
"CSharp" <sm****@asianetindia.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
Hello all,

I have in my project this user control I made:
public class PollControl : System.Web.UI.UserControl

I have properties on its code-behind like:

****************************
private string _name;
private ArrayList _choices;

public string Name
{
get {return _name;}
set {_name=value;}
}
public ArrayList Choices
{
get {return _choices;}
set {_choices=value;}
}
**********************

I added the control to a webform:
<%@ Register TagPrefix="CustCtrl" TagName="Poll" Src="Poll.ascx" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="Poll.WebForm1" %>

<form id="Form1" method="post" runat="server">
<CustCtrl:Poll id="id1" runat="server"
Name="ProgrammingPoll"></CustCtrl:Poll>
</form>

As shown, I can assigne a value to the Name property by specifying a value in the Name attribute in the HTML. But what if I want to programmatically pass an ArrayList to the Choices property from the webform's code-behind?
How can I get a reference at the codebehind to the Poll control I added on the web form HTML interface, so that I can do:

id1.Choices= arrayListXYZ;

Thanks in advance
CSharp


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

88 posts views Thread by Mike | last post: by
2 posts views Thread by Soul | last post: by
5 posts views Thread by vishesh vyas | last post: by
3 posts views Thread by Scott | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.