OnClick Event name for Web page

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
 
A

Andy O'Neill

tshad said:
I am trying to figure out the OnXXXX convention for an event.
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?

asp.net code runs on the server.
( There are exceptions like generated javascript validation, but largely
speacking).
There isn't code running on the client.
So your user changes data on the client, hits the submit button and it goes
back to the server.
Your code then does stuff on the server, sends the page back to the client.
So if you look at it from the 10,000 feet view you have a submit event which
generates the page cycle.
Controls either submit (back to the server) or do nothing in terms of CLR
code events.

In a windows app, the code is running on the client.
So you have click events and well, all sorts.

Since browser based applications are in fashion, people want browser based.
But....
They still use word and excel etc.
So they also want "richly interactive" applications.
In short, they want windows interaction but in a browser.
Which is where ajax and silverlight come in.
Ajax sends bits back to the server, silverlight runs on the client.
 
T

tshad

I understand that but

How do I subscribe from my tag?

I can't seem to get it to show on the aspx page - (OnClick, OnTextChanged
etc)

Thanks,

Tom
 
A

Andy O'Neill

tshad said:
I understand that but

How do I subscribe from my tag?

I can't seem to get it to show on the aspx page - (OnClick, OnTextChanged
etc)


Then you don't understand "that".
You have no events on a web page NONE other than submit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top