PC Review


Reply
Thread Tools Rate Thread

Accessing User Control Event in Main page

 
 
=?Utf-8?B?SXRhbGlhbiBQZXRl?=
Guest
Posts: n/a
 
      29th Aug 2006
Hi,
I have a search bar as a User Control sitting on a Page. The asp web control
search button has its OnClick event set to a method "Search" which sets a
bool isSearch to true.

When I try to access this variable on the main page, it always comes up as
false. I think this is due to the main Page being loaded before the Search
method in the User Control is run.

How am I able to run the Search method in the User Control before the main
Page loads? - or is there a better way of dealing with this situation?

many thanks,

Pete
 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2hpdGVXaXphcmQ=?=
Guest
Posts: n/a
 
      29th Aug 2006
You can 'register' an event in your Page to listen for an event from your
user control by creating a delegate:

public delegate void TestPointSelectedHandler (object sender, ushort
testPointID);

and then create an event in your control that calls the delegate:

public event TestPointSelectedHandler TestPointAdded;

Then raise the event via something like:

TestPointAdded(this, ushort.Parse(strSysID));

In your page you can have something like:

Control1.TestPointAdded += new TestPointSelectedHandler(addTestPoint);

With a method that does something:

private void addTestPoint(object sender, ushort testPointID)
{
// Do some work here
}

HTH

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT


"Italian Pete" wrote:

> Hi,
> I have a search bar as a User Control sitting on a Page. The asp web control
> search button has its OnClick event set to a method "Search" which sets a
> bool isSearch to true.
>
> When I try to access this variable on the main page, it always comes up as
> false. I think this is due to the main Page being loaded before the Search
> method in the User Control is run.
>
> How am I able to run the Search method in the User Control before the main
> Page loads? - or is there a better way of dealing with this situation?
>
> many thanks,
>
> Pete

 
Reply With Quote
 
=?Utf-8?B?SXRhbGlhbiBQZXRl?=
Guest
Posts: n/a
 
      29th Aug 2006

yes this all makes sense. will give it a go. Thanks gandalf.
"WhiteWizard" wrote:

> You can 'register' an event in your Page to listen for an event from your
> user control by creating a delegate:
>
> public delegate void TestPointSelectedHandler (object sender, ushort
> testPointID);
>
> and then create an event in your control that calls the delegate:
>
> public event TestPointSelectedHandler TestPointAdded;
>
> Then raise the event via something like:
>
> TestPointAdded(this, ushort.Parse(strSysID));
>
> In your page you can have something like:
>
> Control1.TestPointAdded += new TestPointSelectedHandler(addTestPoint);
>
> With a method that does something:
>
> private void addTestPoint(object sender, ushort testPointID)
> {
> // Do some work here
> }
>
> HTH
>
> WhiteWizard
> aka Gandalf
> MCSD.NET, MCAD, MCT
>
>
> "Italian Pete" wrote:
>
> > Hi,
> > I have a search bar as a User Control sitting on a Page. The asp web control
> > search button has its OnClick event set to a method "Search" which sets a
> > bool isSearch to true.
> >
> > When I try to access this variable on the main page, it always comes up as
> > false. I think this is due to the main Page being loaded before the Search
> > method in the User Control is run.
> >
> > How am I able to run the Search method in the User Control before the main
> > Page loads? - or is there a better way of dealing with this situation?
> >
> > many thanks,
> >
> > Pete

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event fired by User Control to the main window (form) Samuel Microsoft ASP .NET 2 5th Apr 2009 02:52 PM
How exactly can I get my main page to know that an event was raised on a user control? Gummy Microsoft ASP .NET 2 11th Sep 2006 10:27 PM
Accessing value of dropdown in user control from main page =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= Microsoft ASP .NET 2 22nd Dec 2005 05:27 AM
User Control accessing page =?Utf-8?B?TWljaGVs?= Microsoft C# .NET 2 26th Jan 2005 03:19 PM
How to access values entered in User control in the main page. =?Utf-8?B?dmluZWV0YmF0dGE=?= Microsoft ASP .NET 2 7th Nov 2004 12:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:49 PM.