473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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 1093
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
2
by: Soul | last post by:
Hi, Is there possible for a .aspx page access a user control located in other website? I try to put the full "http" URL of the .ascx file in the Src of "<%@ Register TagPrefix="uc1"...
5
by: vishesh vyas | last post by:
Hi All, I am having a user control consisting of few mandatory fields. How to validate these mandatory fields on the .aspx page submission? Thanks In Advance Regards, Vishesh
4
by: Guadala Harry | last post by:
Is there any way for one Session to remove and update objects in another Session? I seriously doubt it, but thought I'd ask. Here's why: I have some data that is unique per user (or per session -...
3
by: Scott | last post by:
Consider the follow code snippet. Why doesn't it work? // Initialize a CFont object with the characteristics given // in a LOGFONT structure. LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT));...
3
by: anadimpa | last post by:
Hello all I build a javascript function string in the code behind and register it in the Page_Load of my User Control. I do this because I build the javascript based on some variables that are...
9
by: Alan Silver | last post by:
Hello, I have a user control which I am trying to load dynamically, but am running into problems. I think the problem is because I have two .ascx files that refer to the same .ascx.cs file. A...
6
by: ron | last post by:
1. Can I disable a user control in a web page? 2. Can I disable the 'close' function on the top-right corner of a popup window, so I can use code-behind function to close the browser?
2
by: Gugale at Lincoln | last post by:
Hi, I am creating a user control which has a radio button and few other controls. I would like the user control to behave like a radio button, in the sense when added to a container radio button...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.