By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

User Control doubt:

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.