473,326 Members | 2,076 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,326 software developers and data experts.

UserControl reference problem

I neeed to instantiate an UserControl in an aspx page like this:

<MyNamespace:MyControl ID="ctrl1" runat="server" MyParent="<%# this %>" />

where "this" is the current aspx page and should be assigned to
property Parent contained in MyControl class.
Above code is contained in a PlaceHolder.

When debuging, "this" is not null (obviously) but
value in MyParent property's setter is null.
So the reference is not beaing passed.

What am I missing??
I could set this value in OnDataBind but don't know how to get it there from
the aspx page.

I've been reading a number of tutorials on DataBinding, but not found any
solution to this.
Please, help!
Jul 19 '07 #1
1 1575

the Page class does not support databind, so your control has to be
contained in one that does, Repeater, GridView, FormView, etc. then in
the codebehind, you need to call DataBind() on the parent control.

a better approach then using a databinding expression when you are not
using databind, would be to re-engineer MyParent to MyParentID. then you
would just set the parent name in the aspx. in the control code recurse
thru control.Parent.FindControl(parentName) to get the actual control.
if you just want the Page (this), every control has a Page property that
is the Page.

-- bruce (sqlwork.com)

mAbZ wrote:
I neeed to instantiate an UserControl in an aspx page like this:

<MyNamespace:MyControl ID="ctrl1" runat="server" MyParent="<%# this %>" />

where "this" is the current aspx page and should be assigned to
property Parent contained in MyControl class.
Above code is contained in a PlaceHolder.

When debuging, "this" is not null (obviously) but
value in MyParent property's setter is null.
So the reference is not beaing passed.

What am I missing??
I could set this value in OnDataBind but don't know how to get it there from
the aspx page.

I've been reading a number of tutorials on DataBinding, but not found any
solution to this.
Please, help!

Jul 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Meir | last post by:
Hello, I'm new in C# and .net, I'm doing the Walkthrough: Creating a Web User Control that comes with Visual Studio .Net 2003. In this Walkthrough you create a User Control and call it from a...
5
by: Mark Friedman | last post by:
Does anyone know how to reference a subcontrol of a UserControl within client-side script. For example, if I have a TextBox as one of the elements of my UserControl with an id of "MyTextBox", how...
4
by: Mark Friedman | last post by:
I can't seem to figure out how to get a reference to a UserControl in the code-behind for the page that contains the control. All the examples I've seen show how to pass property values from the...
4
by: Joe Molloy | last post by:
Hi, I have a usercontrol containing mutually exclusive radiobuttons and I am trying to use a public function to set a property of the usercontrol based on which one is checked. However when I...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
9
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx");...
3
by: gary | last post by:
Hi, I am trying to reference an anchor in a user control with a url. This worked in 1.1 but no longer works in 2.0. The ascx control is located in a "/include" folder If you have a...
3
by: Jeff | last post by:
Hey ASP.NET 2.0 This the ObjectDataSource in my UserControl, <asp:ObjectDataSource ID="odsMessage" runat="server" SelectMethod="ExecuteMessage" TypeName="AH.MyNetwork.BLL.Network.Message">...
1
by: Nathan Sokalski | last post by:
I have a UserControl that I declare programmatically as follows: Dim userctrl as New rightside_portal() The codebehind file for this UserControl looks like the following: Partial Public...
14
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have created a UserControl ("MyUC"). I've put a bunch of instances of that control on a Page ("Defaul.aspx"). The control works fine. Now, I want to be able to use "FindControl()" from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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.