473,386 Members | 1,817 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,386 software developers and data experts.

User Control Problems, please advise...

Jim
I don't know, maybe I am a moron, which is probably closer to the case,
because I'm having a hard time firing methods from a dynamically loaded user
control. Here is what I'm doing:

1.) Loading the control into a panel using following code:
<code>pnlUserControl.Controls.Add(LoadControl ("userallergy.ascx"));</code>

Now, if I was to use the ClassName directive in my user control, how would I
then instantiate the object in my aspx page so I can use the user control's
user-defined methods? Some of the examples that I have found on the Web are
using in-line C#not the code behind, so it is a little confusing.
Nov 18 '05 #1
1 1121
You can do either this
MyUserControl ctrl = LoadControl("userallergy.ascx") as MyUserControl;
if (ctrl != null)
{
pnlUserControl.Controls.Add(ctrl);
ctrl.UserControlMethod();
}

or
MyUserControl ctrl = pnlUserControl.FindControl("userallergy") as
MyUserControl;
Thanks

"Jim" wrote:
I don't know, maybe I am a moron, which is probably closer to the case,
because I'm having a hard time firing methods from a dynamically loaded user
control. Here is what I'm doing:

1.) Loading the control into a panel using following code:
<code>pnlUserControl.Controls.Add(LoadControl ("userallergy.ascx"));</code>

Now, if I was to use the ClassName directive in my user control, how would I
then instantiate the object in my aspx page so I can use the user control's
user-defined methods? Some of the examples that I have found on the Web are
using in-line C#not the code behind, so it is a little confusing.

Nov 18 '05 #2

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

Similar topics

4
by: Matthew Louden | last post by:
It happend to me more than once. When I create web controls or move the positions in VS.NET, I encountered the following run-time errors: It doesn't matter what controls I create, the following...
13
by: Lloyd Sheen | last post by:
I have now spent 5 hours on google/msdn looking for something useful in the creation of user controls for asp.net. The VS 2003 has very limited support for things such as absolute positioning of...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
4
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
0
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
2
by: Sin Jeong-hun | last post by:
If I create a button like control, then I simply can draw button-like lines on my User Control's surface by getting its Graphics g. If I draw outside of the control's ClientRectangle (for example,...
9
by: abprules | last post by:
Can somehow tell me the best way for multi user development to occur in MS Access? The situation is: We are creating a new database for a small company. There are 2 of us who want to...
2
by: User | last post by:
Hi, I have a custom user control. How do I write the script in a way which i can import custom namespace within the custom control? Please advise.. Thanks! mycontrl.ascx <script...
3
by: XJ | last post by:
Hi Expert, i'm doing some program for my project which using WPF, to create my application more managible i would apply "user control" concept for my project for each section of my workspace. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.