Is it possible to raise event on both the Server and on the Client

T

Tony Johansson

Hello!

There are two kind of server side controls.
1. HTML server side controls when you have the attribute runat=server added
2. WebServer control

On the subject question I would say the following but I'm not 100% sure.
So far as I understand it's only possible to use the HTML server side
control to raise event on both the server and the client.

So can you give me a comment ?

//Tony
 
J

Jeff Johnson

There are two kind of server side controls.
1. HTML server side controls when you have the attribute runat=server
added
2. WebServer control

On the subject question I would say the following but I'm not 100% sure.
So far as I understand it's only possible to use the HTML server side
control to raise event on both the server and the client.

So can you give me a comment ?

My comment is that I THINK you're right when it comes to controls that force
postbacks. Here's why: server-side controls use JavaScript to call a
doPostBack() method (or something like that) and ASP.NET uses the onClick
event of those controls to call that method. In order to respond to events
on the client side you need to provide your own client-side JavaScript and I
don't think you can easily override the JavaScript that is placed into the
onClick handler for a WebServer control, at least not without stepping into
the page lifecycle and writing some very low-level code. So let me amend
that: I'm sure it's POSSIBLE to do it with WebServer controls, but I bet
it's really messy and almost defeats the ease-of-use that WebServer controls
are supposed to provide.

But I'm not an ASP.NET guru....
 
A

andy

Hello!

There are two kind of server side controls.
1. HTML server side controls when you have the attribute runat=server added
2. WebServer control

On the subject question I would say the following but I'm not 100% sure.
So far as I understand it's only possible to use the HTML server side
control to raise event on both the server and the client.

So can you give me a comment ?

//Tony

That's the wrong way to look at it mate.
I don't know what books you're reading but they can't be explaining
stuff very well.

No controls directly raise an event on the server.
Not with asp.net.
There are no events really.
What stuff you're thinking are events do is postback.
It's completely and utterly different from winforms.

Setting stuff like ajax aside.
The server generates some HTML and sends it to the client.
The user does stuff on the client which the server knows nothing
about.
The user submits and sends HTML back to the server.
The server looks at what it gets back and then might do stuff.

The server can find what control posted back and it might kind of look
a bit like a winforms event but you're on your way to all sorts of
trouble if you don't understand the fundamentals first.

Read up on asp.net page life cycle.
And get yourself a decent beginners book, mate.
 
J

Jeff Johnson

The server can find what control posted back and it might kind of
look a bit like a winforms event but you're on your way to all sorts
of trouble if you don't understand the fundamentals first.

That's misleading. Events are not something specific to WinForms; they are
part and parcel of the C# language. Events are most definitely raised during
ASP.NET page processing.
 

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

Top