T
tshad
I am trying to figure out the OnXXXX convention for an event.
It doesn't seem to be needed in an Windows Form page.
But it seems to be needed on a web page.
If I set up a User Control as so:
******************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public delegate void OwnerChangedEventHandler(string newOwner);
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public event OwnerChangedEventHandler OwnerChanged;
private string owner;
protected void Page_Load(object sender, EventArgs e)
{
}
public string CarOwner
{
get { return this.owner; }
set
{
this.owner = value;
if (this.OwnerChanged != null)
this.OwnerChanged(value);
}
}
}
}
******************************************************
In my asp.net page I have:
********************************************************
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication2._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagPrefix="uc" TagName="Spinner" Src="~/WebUserControl1.ascx"
%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:Spinner id="Spinner1" runat="server" />
</div>
</form>
</body>
</html>
********************************************************
In my Page_Load, if I do:
Spinner1.
Intellisense shows me my event: OwnerChanged.
But if I put a space in my "<uc:Spinner" tag, I get a whole bunch of OnXXXX
selections in Intellisense but no "OnOwnerChanged:" or "OwnerChanged".
So I can subscribe to my event in my Page_Unload as:
Spinner1.OwnerChanged += car_OwnerChanged;
But I can't seem to do the same from my uc:Spinner tag.
Why is that?
I also tried to add the following to my code page and intellisense still
doesn't see it (I did it as protected and public).
protected virtual void OnOwnerChanged(EventArgs e)
{
}
Thanks,
Tom
It doesn't seem to be needed in an Windows Form page.
But it seems to be needed on a web page.
If I set up a User Control as so:
******************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public delegate void OwnerChangedEventHandler(string newOwner);
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public event OwnerChangedEventHandler OwnerChanged;
private string owner;
protected void Page_Load(object sender, EventArgs e)
{
}
public string CarOwner
{
get { return this.owner; }
set
{
this.owner = value;
if (this.OwnerChanged != null)
this.OwnerChanged(value);
}
}
}
}
******************************************************
In my asp.net page I have:
********************************************************
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication2._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagPrefix="uc" TagName="Spinner" Src="~/WebUserControl1.ascx"
%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:Spinner id="Spinner1" runat="server" />
</div>
</form>
</body>
</html>
********************************************************
In my Page_Load, if I do:
Spinner1.
Intellisense shows me my event: OwnerChanged.
But if I put a space in my "<uc:Spinner" tag, I get a whole bunch of OnXXXX
selections in Intellisense but no "OnOwnerChanged:" or "OwnerChanged".
So I can subscribe to my event in my Page_Unload as:
Spinner1.OwnerChanged += car_OwnerChanged;
But I can't seem to do the same from my uc:Spinner tag.
Why is that?
I also tried to add the following to my code page and intellisense still
doesn't see it (I did it as protected and public).
protected virtual void OnOwnerChanged(EventArgs e)
{
}
Thanks,
Tom