Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Access info from a usercontrol

Reply
Thread Tools

Access info from a usercontrol

 
 
Dave
Guest
Posts: n/a
 
      12-03-2004
Hi all,

I am still fairly new to dot net, so go easy...

Anyway,

I have my main page. In this page is a usercontrol that
manages the security of the page.

I am authenticating a user against Content Management
Server, then checking locally if they have specific
rights to content on that page.

My class in the usercontrol is...


################################################## ########
public class UserAuthenticationAndTracking :
System.Web.UI.UserControl
{

SqlConnection conn = new SqlConnection
(ConfigurationSettings.AppSettings["conn"]);


private bool UserApproved;

private void Page_Load(object sender,
System.EventArgs e)
{
// Put user code to initialize
the page here

DataSet DS = new DataSet();

if (!IsPostBack)
{
if
(CmsHttpContext.Current.User != null)
{
try
{
conn.Open
();

SqlCommand UserData = new SqlCommand("select *
from extranetUserDetails where UserApproved = 1 and
UserName = @UserName", conn);

UserData.Parameters.Add("@UserName",
SqlDbType.NVarChar).Value =
CmsHttpContext.Current.User.ToString();

SqlDataReader readData = UserData.ExecuteReader();

if
(readData.HasRows)
{

userApproved = true;
}
else
{

userApproved = false;
}
Trace.Warn
("Authenticated", UserApproved.ToString());

}
finally
{
conn.Close
();
}
}
}

}

public bool userApproved
{
get
{
return UserApproved;
}

set
{
UserApproved = value;
}
}


################################################## ########


In my page, (.aspx) I want to see if the user is approved.

I am trying...

################################################## ########

if
(UserAuthenticationAndTracking.userApproved)
{
txtUserName.Text
+= " USER APPROVED";
}
else
{
txtUserName.Text
+= " USER NOT APPROVED";
}

################################################## ########


but when I compile, I am getting...

C:\Inetpub\wwwroot\MyCMSApp\Templates\nqt.aspx.cs( 37): An
object reference is required for the nonstatic field,
method, or
property 'MyCMSApp.CMSUserControls.UserAuthenticationAndTr
acking.userApproved'


Am I missing something???

Previously, I had tried to just access a public variable
in the usercontrol, but that didn't work either.

Also, may be of assistance, when I type
UserAuthenticationAndTracking, I do not get the property
in the intellisense.

What I need to do is to make the userApproved status to
any other user controls and the page. I don't know if I
am going about it in the right way, so any assistance
will be very much appreciated.

Best regards,
David Colliver.
http://www.DerbyFOCUS.com


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      12-03-2004
"Dave" <(E-Mail Removed)> wrote in message
news:0cbd01c4d926$b6060910$(E-Mail Removed)...
> Hi all,
>
> I am still fairly new to dot net, so go easy...
>
> Anyway,
>
> I have my main page. In this page is a usercontrol that
> manages the security of the page.
>
> I am authenticating a user against Content Management
> Server, then checking locally if they have specific
> rights to content on that page.
>
> My class in the usercontrol is...
>
>
> ################################################## ########
> public class UserAuthenticationAndTracking :
> System.Web.UI.UserControl


....

> public bool userApproved
> {
> get
> {
> return UserApproved;
> }
>
> set
> {
> UserApproved = value;
> }
> }
>
>
> ################################################## ########
>
>
> In my page, (.aspx) I want to see if the user is approved.
>
> I am trying...
>
> ################################################## ########
>
> if
> (UserAuthenticationAndTracking.userApproved)


....

> but when I compile, I am getting...
>
> C:\Inetpub\wwwroot\MyCMSApp\Templates\nqt.aspx.cs( 37): An
> object reference is required for the nonstatic field,
> method, or
> property 'MyCMSApp.CMSUserControls.UserAuthenticationAndTr
> acking.userApproved'
>
>
> Am I missing something???


Yes.

UserAuthenticationAndTracking is a class. That's different from being an
instance of a class, which is what you need.

If it's not already declared in the codebehind of your page, try declaring
this:

protected UserAuthenticationAndTracking userAuthenticationAndTracking;

You should then be able to access
"userAuthenticationAndTracking.userApproved".


BTW, the usual naming conventions have properties and methods declared with
a leading capital, so it should be UserApproved for the property, and
perhaps userApproved for the private variable. I personally would use
_userApproved for the private member.

Also BTW, good work on using a property. A lot of people don't figure that
one out. And I assume you already know about putting events inside of user
controls...


John Saunders


 
Reply With Quote
 
 
 
 
Dave
Guest
Posts: n/a
 
      12-03-2004
Hi John,

Thanks for your reply.

I have put the protected line into my .aspx, though in
the intellisense, the property still isn't appearing. Any
reason for that?

I am still getting used to the coding conventions, I am
mostly there, (camel case and that other one...).

Events in user controls??? I think I am doing this, but
not sure if I am doing it right. Can you supply a quick
example? (I am not sure if you mean events controlled by
components of a user control, or events controlled by
components of the page that hosts the user control)

In this particular case, this control probably won't need
an event, apart from the page load. All I am doing is
some basic authentication and tracking.

I have other problems at the minute as well, but is OT.
(The problem is that I am creating a DB connection,
querying into a datareader, then based on values in the
database, do other DB work, using the same connection. In
classic ASP, I can re-use the connection, but for some
reason, I can't in this case.)

Best regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com


>-----Original Message-----
>"Dave" <(E-Mail Removed)> wrote in

message
>news:0cbd01c4d926$b6060910$(E-Mail Removed)...
>> Hi all,
>>
>> I am still fairly new to dot net, so go easy...
>>
>> Anyway,
>>
>> I have my main page. In this page is a usercontrol that
>> manages the security of the page.
>>
>> I am authenticating a user against Content Management
>> Server, then checking locally if they have specific
>> rights to content on that page.
>>
>> My class in the usercontrol is...


<snip>

>Also BTW, good work on using a property. A lot of people

don't figure that
>one out. And I assume you already know about putting

events inside of user
>controls...
>
>
>John Saunders
>
>
>.
>

 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      12-03-2004
I just had one of those D'oh!!! moments.

I hadn't noticed that you called the instance of the
class with a lower case U.

Regards,
Dave.

>-----Original Message-----
>Hi John,
>
>Thanks for your reply.
>
>I have put the protected line into my .aspx, though in
>the intellisense, the property still isn't appearing.

Any
>reason for that?
>
>I am still getting used to the coding conventions, I am
>mostly there, (camel case and that other one...).
>
>Events in user controls??? I think I am doing this, but
>not sure if I am doing it right. Can you supply a quick
>example? (I am not sure if you mean events controlled by
>components of a user control, or events controlled by
>components of the page that hosts the user control)
>
>In this particular case, this control probably won't

need
>an event, apart from the page load. All I am doing is
>some basic authentication and tracking.
>
>I have other problems at the minute as well, but is OT.
>(The problem is that I am creating a DB connection,
>querying into a datareader, then based on values in the
>database, do other DB work, using the same connection.

In
>classic ASP, I can re-use the connection, but for some
>reason, I can't in this case.)
>
>Best regards,
>Dave Colliver.
>http://www.BlackpoolFOCUS.com
>
>
>>-----Original Message-----
>>"Dave" <(E-Mail Removed)> wrote in

>message
>>news:0cbd01c4d926$b6060910$(E-Mail Removed)...
>>> Hi all,
>>>
>>> I am still fairly new to dot net, so go easy...
>>>
>>> Anyway,
>>>
>>> I have my main page. In this page is a usercontrol

that
>>> manages the security of the page.
>>>
>>> I am authenticating a user against Content Management
>>> Server, then checking locally if they have specific
>>> rights to content on that page.
>>>
>>> My class in the usercontrol is...

>
><snip>
>
>>Also BTW, good work on using a property. A lot of

people
>don't figure that
>>one out. And I assume you already know about putting

>events inside of user
>>controls...
>>
>>
>>John Saunders
>>
>>
>>.
>>

>.
>

 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      12-03-2004
Still got a slight problem.

It now compiles, but I get...
Object reference not set to an instance of an object.
on the line where I try to use it (the .userApproved)

Regards,
Dave Colliver.
http://www.HullFOCUS.com

>-----Original Message-----
>"Dave" <(E-Mail Removed)> wrote in

message
>news:0cbd01c4d926$b6060910$(E-Mail Removed)...
>> Hi all,
>>
>> I am still fairly new to dot net, so go easy...
>>
>> Anyway,
>>
>> I have my main page. In this page is a usercontrol that
>> manages the security of the page.
>>
>> I am authenticating a user against Content Management
>> Server, then checking locally if they have specific
>> rights to content on that page.
>>
>> My class in the usercontrol is...
>>
>>
>>

################################################## ########
>> public class UserAuthenticationAndTracking :
>> System.Web.UI.UserControl

>
>....
>
>> public bool userApproved
>> {
>> get
>> {
>> return UserApproved;
>> }
>>
>> set
>> {
>> UserApproved = value;
>> }
>> }
>>
>>
>>

################################################## ########
>>
>>
>> In my page, (.aspx) I want to see if the user is

approved.
>>
>> I am trying...
>>
>>

################################################## ########
>>
>> if
>> (UserAuthenticationAndTracking.userApproved)

>
>....
>
>> but when I compile, I am getting...
>>
>> C:\Inetpub\wwwroot\MyCMSApp\Templates\nqt.aspx.cs( 37):

An
>> object reference is required for the nonstatic field,
>> method, or
>>

property 'MyCMSApp.CMSUserControls.UserAuthenticationAndTr
>> acking.userApproved'
>>
>>
>> Am I missing something???

>
>Yes.
>
>UserAuthenticationAndTracking is a class. That's

different from being an
>instance of a class, which is what you need.
>
>If it's not already declared in the codebehind of your

page, try declaring
>this:
>
>protected UserAuthenticationAndTracking

userAuthenticationAndTracking;
>
>You should then be able to access
>"userAuthenticationAndTracking.userApproved".
>
>
>BTW, the usual naming conventions have properties and

methods declared with
>a leading capital, so it should be UserApproved for the

property, and
>perhaps userApproved for the private variable. I

personally would use
>_userApproved for the private member.
>
>Also BTW, good work on using a property. A lot of people

don't figure that
>one out. And I assume you already know about putting

events inside of user
>controls...
>
>
>John Saunders
>
>
>.
>

 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      12-03-2004
"Dave" <(E-Mail Removed)> wrote in message
news:0ead01c4d949$cf02be40$(E-Mail Removed)...
> Hi John,
>
> Thanks for your reply.
>
> I have put the protected line into my .aspx, though in
> the intellisense, the property still isn't appearing. Any
> reason for that?


Sorry, I don't know.

> I am still getting used to the coding conventions, I am
> mostly there, (camel case and that other one...).
>
> Events in user controls??? I think I am doing this, but
> not sure if I am doing it right. Can you supply a quick
> example? (I am not sure if you mean events controlled by
> components of a user control, or events controlled by
> components of the page that hosts the user control)


I meant an event generated by the user control. The idea would be that the
user control tells the page that something has happened, then the page can
use the properties of the user control to do something about it.

John Saunders


 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      12-03-2004
"Dave" <(E-Mail Removed)> wrote in message
news:04de01c4d94f$b6676650$(E-Mail Removed)...
> Still got a slight problem.
>
> It now compiles, but I get...
> Object reference not set to an instance of an object.
> on the line where I try to use it (the .userApproved)


Dave, here's some code that's working for me in VS2003:

WebForm1.aspx.cs:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace UserControls
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected WebUserControl1 WebUserControl11;

private void Page_Load(object sender, System.EventArgs e)
{
WebUserControl11.SomeInteger += 1; // There _will_ be a
quiz...
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);

WebUserControl11.MyButtonClicked += new
EventHandler(WebUserControl11_MyButtonClicked);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void WebUserControl11_MyButtonClicked(object sender,
EventArgs e)
{
Label1.Text = "WebUserControl11.SomeInteger = " +
WebUserControl11.SomeInteger.ToString();
}
}
}

WebUserControl1.ascx.cs:

namespace UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for WebUserControl1.
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
private int _someInteger;

protected System.Web.UI.WebControls.Button Button1;

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new
System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public event EventHandler MyButtonClicked;

protected virtual void OnMyButtonClicked(EventArgs e)
{
if (MyButtonClicked != null)
{
MyButtonClicked(this, e);
}
}

public int SomeInteger
{
get {return _someInteger;}
set {_someInteger = value;}
}

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

private void Button1_Click(object sender, System.EventArgs e)
{
OnMyButtonClicked(e); // or EventArgs.Empty, or new
EventArgs()
}
}
}

Give that a try and see if it works for you.

John Saunders


 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      12-06-2004
Hi John,

I have done this in the past and have the usercontrols
working.

In this instance, I am not sure what is going off. I am
wondering if it is something to do with the page
execution path.

At the moment, in the page, I have the page_load. In
here, I am checking the validity of the authentication.

In my user control, I have in the page_load, the database
check to get the user and the users parameters. On
checking the parameters for the user, I set the property
to true or false.

Back to the page, if I check the value in the property, I
am wondering if it is not known at this point, which if
the page page_load runs first, then that will probably be
true.

In my page, I have...


protected
MyCMSApp.CMSUserControls.UserAuthenticationAndTrac king
userAuthenticationAndTracking;

private void Page_Load(object sender, System.EventArgs e)
{

Trace.Warn("PAGE:Approved",
userAuthenticationAndTracking.userApproved.ToStrin g());


As I type the userAuthenticationAndTracking. I am getting
the intellisense showing me the options, of which
userApproved is one of them.

Thanks for your help so far.

Best regards,
Dave Colliver.
http://www.LiverpoolFOCUS.com

>-----Original Message-----
>"Dave" <(E-Mail Removed)> wrote in

message
>news:04de01c4d94f$b6676650$(E-Mail Removed)...
>> Still got a slight problem.
>>
>> It now compiles, but I get...
>> Object reference not set to an instance of an object.
>> on the line where I try to use it (the .userApproved)

>
>Dave, here's some code that's working for me in VS2003:
>
>WebForm1.aspx.cs:
>
>using System;
>using System.Collections;
>using System.ComponentModel;
>using System.Data;
>using System.Drawing;
>using System.Web;
>using System.Web.SessionState;
>using System.Web.UI;
>using System.Web.UI.WebControls;
>using System.Web.UI.HtmlControls;
>
>namespace UserControls
>{
> /// <summary>
> /// Summary description for WebForm1.
> /// </summary>
> public class WebForm1 : System.Web.UI.Page
> {
> protected System.Web.UI.WebControls.Label Label1;
> protected WebUserControl1 WebUserControl11;
>
> private void Page_Load(object sender,

System.EventArgs e)
> {
> WebUserControl11.SomeInteger += 1; //

There _will_ be a
>quiz...
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the

ASP.NET Web Form
>Designer.
> //
> InitializeComponent();
> base.OnInit(e);
>
> WebUserControl11.MyButtonClicked += new
>EventHandler(WebUserControl11_MyButtonClicked);
> }
>
> /// <summary>
> /// Required method for Designer support - do

not modify
> /// the contents of this method with the code

editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Load += new System.EventHandler

(this.Page_Load);
>
> }
> #endregion
>
> private void WebUserControl11_MyButtonClicked

(object sender,
>EventArgs e)
> {
> Label1.Text = "WebUserControl11.SomeInteger

= " +
>WebUserControl11.SomeInteger.ToString();
> }
> }
>}
>
>WebUserControl1.ascx.cs:
>
>namespace UserControls
>{
> using System;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.UI.WebControls;
> using System.Web.UI.HtmlControls;
>
> /// <summary>
> /// Summary description for WebUserControl1.
> /// </summary>
> public class WebUserControl1 :

System.Web.UI.UserControl
> {
> private int _someInteger;
>
> protected System.Web.UI.WebControls.Button

Button1;
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the

ASP.NET Web Form
>Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support -

do not modify
> /// the contents of this method with the

code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Button1.Click += new
>System.EventHandler(this.Button1_Click);
> this.Load += new System.EventHandler

(this.Page_Load);
>
> }
> #endregion
>
> public event EventHandler MyButtonClicked;
>
> protected virtual void OnMyButtonClicked

(EventArgs e)
> {
> if (MyButtonClicked != null)
> {
> MyButtonClicked(this, e);
> }
> }
>
> public int SomeInteger
> {
> get {return _someInteger;}
> set {_someInteger = value;}
> }
>
> private void Page_Load(object sender,

System.EventArgs e)
> {
> // Put user code to initialize the page here
> }
>
> private void Button1_Click(object sender,

System.EventArgs e)
> {
> OnMyButtonClicked(e); // or

EventArgs.Empty, or new
>EventArgs()
> }
> }
>}
>
>Give that a try and see if it works for you.
>
>John Saunders
>
>
>.
>

 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      12-06-2004
Hi again,

There is an added complication that I have just realised
(whilst doing a bit of research...)

I am breaking the page into bits, for templating.

I have a topbar, a leftbar and a rightbar. I am putting
these in usercontrols (like include files in classic asp)

This got me thinking, the top bar will ALWAYS be
consistent and ALWAYS in a page, so why shouldn't I put
my authentication user control in the top bar control.

so it is like...

Page
Top Bar Control
Authentication Control

The topbar control has nothing refrencing the user
control EXCEPT for what is in the ASPX
<%@ Register TagPrefix="uc1"
TagName="UserAuthenticationAndTracking"
Src="UserAuthenticationAndTracking.ascx" %>

I guess that my UC is working correctly, as I know it is
accessing the database. In this revised scenario, is
there anything else I need to do?

Thanks for your assistance and apologies for the
confusion.

Best regards,
Dave Colliver.
http://www.Burton-on-TrentFOCUS.com

>-----Original Message-----
>Hi John,
>
>I have done this in the past and have the usercontrols
>working.
>
>In this instance, I am not sure what is going off. I am
>wondering if it is something to do with the page
>execution path.
>
>At the moment, in the page, I have the page_load. In
>here, I am checking the validity of the authentication.
>
>In my user control, I have in the page_load, the

database
>check to get the user and the users parameters. On
>checking the parameters for the user, I set the property
>to true or false.
>
>Back to the page, if I check the value in the property,

I
>am wondering if it is not known at this point, which if
>the page page_load runs first, then that will probably

be
>true.
>
>In my page, I have...
>
>
>protected
>MyCMSApp.CMSUserControls.UserAuthenticationAndTra cking
>userAuthenticationAndTracking;
>
>private void Page_Load(object sender, System.EventArgs e)
>{
>
>Trace.Warn("PAGE:Approved",
>userAuthenticationAndTracking.userApproved.ToStri ng());
>
>
>As I type the userAuthenticationAndTracking. I am

getting
>the intellisense showing me the options, of which
>userApproved is one of them.
>
>Thanks for your help so far.
>
>Best regards,
>Dave Colliver.
>http://www.LiverpoolFOCUS.com
>
>>-----Original Message-----
>>"Dave" <(E-Mail Removed)> wrote in

>message
>>news:04de01c4d94f$b6676650$(E-Mail Removed)...
>>> Still got a slight problem.
>>>
>>> It now compiles, but I get...
>>> Object reference not set to an instance of an object.
>>> on the line where I try to use it (the .userApproved)

>>
>>Dave, here's some code that's working for me in VS2003:
>>
>>WebForm1.aspx.cs:
>>
>>using System;
>>using System.Collections;
>>using System.ComponentModel;
>>using System.Data;
>>using System.Drawing;
>>using System.Web;
>>using System.Web.SessionState;
>>using System.Web.UI;
>>using System.Web.UI.WebControls;
>>using System.Web.UI.HtmlControls;
>>
>>namespace UserControls
>>{
>> /// <summary>
>> /// Summary description for WebForm1.
>> /// </summary>
>> public class WebForm1 : System.Web.UI.Page
>> {
>> protected System.Web.UI.WebControls.Label

Label1;
>> protected WebUserControl1 WebUserControl11;
>>
>> private void Page_Load(object sender,

>System.EventArgs e)
>> {
>> WebUserControl11.SomeInteger +=

1; //
>There _will_ be a
>>quiz...
>> }
>>
>> #region Web Form Designer generated code
>> override protected void OnInit(EventArgs e)
>> {
>> //
>> // CODEGEN: This call is required by the

>ASP.NET Web Form
>>Designer.
>> //
>> InitializeComponent();
>> base.OnInit(e);
>>
>> WebUserControl11.MyButtonClicked += new
>>EventHandler(WebUserControl11_MyButtonClicked) ;
>> }
>>
>> /// <summary>
>> /// Required method for Designer support - do

>not modify
>> /// the contents of this method with the code

>editor.
>> /// </summary>
>> private void InitializeComponent()
>> {
>> this.Load += new System.EventHandler

>(this.Page_Load);
>>
>> }
>> #endregion
>>
>> private void WebUserControl11_MyButtonClicked

>(object sender,
>>EventArgs e)
>> {
>> Label1.Text = "WebUserControl11.SomeInteger

>= " +
>>WebUserControl11.SomeInteger.ToString();
>> }
>> }
>>}
>>
>>WebUserControl1.ascx.cs:
>>
>>namespace UserControls
>>{
>> using System;
>> using System.Data;
>> using System.Drawing;
>> using System.Web;
>> using System.Web.UI.WebControls;
>> using System.Web.UI.HtmlControls;
>>
>> /// <summary>
>> /// Summary description for WebUserControl1.
>> /// </summary>
>> public class WebUserControl1 :

>System.Web.UI.UserControl
>> {
>> private int _someInteger;
>>
>> protected System.Web.UI.WebControls.Button

>Button1;
>>
>> #region Web Form Designer generated code
>> override protected void OnInit(EventArgs e)
>> {
>> //
>> // CODEGEN: This call is required by the

>ASP.NET Web Form
>>Designer.
>> //
>> InitializeComponent();
>> base.OnInit(e);
>> }
>>
>> /// <summary>
>> /// Required method for Designer

support -
> do not modify
>> /// the contents of this method with the

>code editor.
>> /// </summary>
>> private void InitializeComponent()
>> {
>> this.Button1.Click += new
>>System.EventHandler(this.Button1_Click);
>> this.Load += new System.EventHandler

>(this.Page_Load);
>>
>> }
>> #endregion
>>
>> public event EventHandler MyButtonClicked;
>>
>> protected virtual void OnMyButtonClicked

>(EventArgs e)
>> {
>> if (MyButtonClicked != null)
>> {
>> MyButtonClicked(this, e);
>> }
>> }
>>
>> public int SomeInteger
>> {
>> get {return _someInteger;}
>> set {_someInteger = value;}
>> }
>>
>> private void Page_Load(object sender,

>System.EventArgs e)
>> {
>> // Put user code to initialize the page here
>> }
>>
>> private void Button1_Click(object sender,

>System.EventArgs e)
>> {
>> OnMyButtonClicked(e); // or

>EventArgs.Empty, or new
>>EventArgs()
>> }
>> }
>>}
>>
>>Give that a try and see if it works for you.
>>
>>John Saunders
>>
>>
>>.
>>

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Getting a property of a control inside a usercontrol, from another usercontrol Fabiano ASP .Net 2 06-03-2005 09:56 AM
accessing usercontrol from another usercontrol Phl ASP .Net 2 11-18-2004 07:33 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments