Create an event

  • Thread starter Thread starter Dan Aldean
  • Start date Start date
D

Dan Aldean

Hi,

I create a WEB application and I use a textbox, server control.
It does not have an OnClick event. Is it possible to create one?

Thanks
 
Explain how you would use a textbox that would trigger a server
side postback on the onclick event?

Once you clicked inside the textbox each time, it would post
back to the server.

How would you ever use something like that?

You can add html client side events by adding to
the .Attributes collection of the control though.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
 
Hi Dan,

If you want a client-side click event then use onclick in the declaration and run some javascript:

<asp:textbox runat="server" id="txtClickable" onclick="alert('clicked!');" text="[click into me for an alert]" />

If you want a server-side click event you could derive a class from TextBox and implement IPostBackEventHandler. Use the
ClientScriptManager (Page.ClientScript) to render a post-back reference in the onclick attribute's javascript (.NET 2.0) or by using
a method of the Page class (.NET 1.*). In each case the method is called GetPostBackEventReference, and it will write javascript
that causes the page to be posted back and the RaisePostBackEvent method to be invoked on your class, where you can raise your
custom Click event. Be careful here, however, because your TextBox will not be useable on the client if you always render the
onclick javascript to post back. This is because each time the user clicks in your box, it will post back to the server and they
will never be able to actually enter text. And if you call txtClickable.Focus() in the 2.0 framework, it might be an endless
post-back loop!
 
Dan,

You can set it in the property box autopostback to true


Cor
 

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

Back
Top