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

Calling Usercontrol function

Hi

How can you call a function on a user control(.ascx) ? what is the syntax
for this?

thanks

Bert
Dec 3 '06 #1
3 4012

Bert wrote:
Hi

How can you call a function on a user control(.ascx) ? what is the syntax
for this?

thanks

Bert
Hi...

Write function in your user control with public access specifier. Then
from page call the function from the instance of the user control...

Suppose you have a user control Search.ascx and in the user control you
have a function

public void DoSomeWork()
{
///Perform some operation
///This is a usercontrol function
}

And in the aspx page you can access...

protected void Page_Load(object sender, EventArgs e)
{
Search1.DoSomeWork();
}

just like that...

Thanks

Masudur
Kaz Software Ltd.
www.kaz.com.bd

Dec 3 '06 #2
forgot this:
my usercontrol is loaded into a placeholder, so how do you call it then from
this aspx page:

Dim uc as Control
uc = me.loadcontrol("myusercontrol.ascx")
me.MyPlaceholder.add(uc)

Say myusercontrol.ascx had a sub dosomething(), how do you call this
dosomething sub from the page?

thanks
"Masudur" <mu*****@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
>
Bert wrote:
>Hi

How can you call a function on a user control(.ascx) ? what is the syntax
for this?

thanks

Bert

Hi...

Write function in your user control with public access specifier. Then
from page call the function from the instance of the user control...

Suppose you have a user control Search.ascx and in the user control you
have a function

public void DoSomeWork()
{
///Perform some operation
///This is a usercontrol function
}

And in the aspx page you can access...

protected void Page_Load(object sender, EventArgs e)
{
Search1.DoSomeWork();
}

just like that...

Thanks

Masudur
Kaz Software Ltd.
www.kaz.com.bd

Dec 3 '06 #3
You need to strongly type the user control when you load it. I'm going to do
it in C# as I haven't used VB in a few years.

MySite.MyControl uc =
(MySite.MyControl)me.loadcontrol("myusercontrol.as cx");
uc.MyFunction();

You could also use reflection to do it, but reflection can be a lot slower.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Bert" <be****@gmail.comwrote in message
news:eN*************@TK2MSFTNGP06.phx.gbl...
Hi

How can you call a function on a user control(.ascx) ? what is the syntax
for this?

thanks

Bert

Dec 3 '06 #4

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

Similar topics

3
by: Dave McCracken | last post by:
I am hosting .Net UserControls in HTML pages with Object Tags. These UserControls are clients of remotable objects that run on the same machine. The remote objects execute callbacks via sponsor...
1
by: JezB | last post by:
In my Page_Load event of all my web app Pages and UserControls I instantiate the same library class "TextResources" (to take care of reading presentation text strings from localizable resource...
3
by: phl | last post by:
hi, I have a number of usercontrols which inherits a interface. the function in this interface is used to provide information about the usercontrol. I would like to call this function say when a...
3
by: Peter Rilling | last post by:
Okay, I am probably missing something simple so here is my problem. I have a page. On this page I have a usercontrol. On this user control I have another usercontrol. On each usercontrol I...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
0
by: oliver | last post by:
QUESTION: How to access an object embedded in a UserControl through Javascript file? Another way to ask this question: How to execute script from a UserControl, accessing other objects in that...
2
by: fillic2002 | last post by:
Hi I have a query related to the VS2005 usercontrol. As i have two different usercontrol in a single master page say uc1 and uc2. Now i am calling a function of uc1 from uc2. what is the best...
2
by: gerry | last post by:
based on MSPress's ASP.NET 2.0 Applications Advaced Topics ( Table 12-3 p.472 ), and most events should be automatically wired up when @Control AutoEventWireup="true". ie. Page_InitComplete() {}...
5
by: Blue | last post by:
We have a custom word processing type editor built with C# and .NET 2.0 and we need to support typing in languages other than English. I want to be able to use the Windows IME to enter in text...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.