473,396 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

raising events in a user control ???

Hi,

I have a textbox in a web user control.
I then add the usercontrol to a web form. I also add a label in the
web form.

Now, when I press a key in the textbox, i want to display some text in
the label.

I tried by raising events as used in Winforms but it is not as easy as
that apparently.

Any ideas?

thank you
Chris
Jul 20 '08 #1
7 2856
HI,

Here is what you will do...

first you got to set your textbox's autopostback property to true.

next you will add textchange event hanlder of textbox...

add a public demo event in user control... (example : public event
eventhanlder textchangeonusercontrol;)

then in textchange event hanlder fire the textchangeonusercontrol
event like

if(textchangeonusercontrol!=null)
{
textchangeonusercontrol("stringvalue",e);
}

in page... subscribe the event of the user control...

and when the event is raise... change the value of the lable from
sender argument

example ( string value = sender as string; lable.text = value;
Best of luck

-------
Munna

www.munna.shatkotha.com/blog
www.munna.shatkotha.com
www.shatkotha.com
Jul 21 '08 #2
Hi

you might also check out this blog post

http://codebetter.com/blogs/brendan....-Controls.aspx

Best of luck

-------
Munna

www.munna.shatkotha.com/blog
www.munna.shatkotha.com
www.shatkotha.com
Jul 21 '08 #3
On Jul 21, 8:10 am, Munna <munna...@gmail.comwrote:
Hi

you might also check out this blog post

http://codebetter.com/blogs/brendan....04/10/06/Easil...

Best of luck

-------
Munna

http://www.munna.shatkotha.com/blogw....shatkotha.com
Thank you for your reply !

That works fine.

An additional question I have: is there a way to implement it without
the Autopostback of the textbox set to true?
In other words I'd like to handle it on the client, thus with
javascript as well.
so intercept the 'onkeypress' event (that I can do) but then fire the
event to the parent form (which i think has to be done with ASP.NET.)

Any idea?

thank you
Chris
Jul 21 '08 #4
Christian Cambier wrote:
Hi,

I have a textbox in a web user control.
I then add the usercontrol to a web form. I also add a label in the
web form.

Now, when I press a key in the textbox, i want to display some text in
the label.

I tried by raising events as used in Winforms but it is not as easy as
that apparently.

Any ideas?

thank you
Chris
If you want to raise a server event for every key press, the page will
be reloaded for every key that you press, which is not very practical.
For something simple like displaying some text on the page, you should
use a client event instead, i.e. Javascript.

Example:

onkeydown="document.getElementById('ElementForShow ingMessage').innerHTML='message';"

--
Göran Andersson
_____
http://www.guffa.com
Jul 21 '08 #5
On Jul 21, 11:25 am, Göran Andersson <gu...@guffa.comwrote:
Christian Cambier wrote:
Hi,
I have a textbox in a web user control.
I then add the usercontrol to a web form. I also add a label in the
web form.
Now, when I press a key in the textbox, i want to display some text in
the label.
I tried by raising events as used in Winforms but it is not as easy as
that apparently.
Any ideas?
thank you
Chris

If you want to raise a server event for every key press, the page will
be reloaded for every key that you press, which is not very practical.
For something simple like displaying some text on the page, you should
use a client event instead, i.e. Javascript.

Example:

onkeydown="document.getElementById('ElementForShow ingMessage').innerHTML='message';"

--
Göran Andersson
_____http://www.guffa.com
Hello,

that is to set the text of a control Ok, but my situation is a little
more complicated than that ... allow me to explain what I really try
to implement.

I am creating a simple calculator to add 2 values.
For the user to enter a value, I have created a web user control
consisting of a textbox and some additional logic.

I add 2 of those webuser control on an asp.net form, one for each
value.
added as well ON THE FORM (and not in the user control) are a button
(Add) and a label to display the result
Now, i run it ... enter 2 values, press Add and the result is
displayed in the label ... easy.

But what i want now is that when I change one of the values in one of
the textboxes in the user control (during 'onkeypress' in javascript)
is that the text in the label control is cleared.
for this to happen, I can not just implement it in the onkeypress of
the textbox, since the label control is not part of the user control
you see?

so what I need, I think, is to raise some event in onkeypress (in the
webuser control) and implement the event handler in the host form but
whithout a postback to the server !

any ideas?

Chris
Jul 22 '08 #6
this is a poor design in a web application. raising an event on the
server requires the browser posting all form data to the server, the
server processing the page logic, and sending a new html page to be
displayed at the browser, then the browser rerendering the whole page.
you could use an ajax library to reduce the amount of rerendering the
browser does, but it is still too much overhead to process on a keystoke
basis.

this should all be done in client script. the bookstore is full of
javascript books, any of which should teach you enough to code this
simple of a task.

-- bruce (sqlwork.com)
Christian Cambier wrote:
On Jul 21, 11:25 am, Göran Andersson <gu...@guffa.comwrote:
>Christian Cambier wrote:
>>Hi,
I have a textbox in a web user control.
I then add the usercontrol to a web form. I also add a label in the
web form.
Now, when I press a key in the textbox, i want to display some text in
the label.
I tried by raising events as used in Winforms but it is not as easy as
that apparently.
Any ideas?
thank you
Chris
If you want to raise a server event for every key press, the page will
be reloaded for every key that you press, which is not very practical.
For something simple like displaying some text on the page, you should
use a client event instead, i.e. Javascript.

Example:

onkeydown="document.getElementById('ElementForSho wingMessage').innerHTML='message';"

--
Göran Andersson
_____http://www.guffa.com

Hello,

that is to set the text of a control Ok, but my situation is a little
more complicated than that ... allow me to explain what I really try
to implement.

I am creating a simple calculator to add 2 values.
For the user to enter a value, I have created a web user control
consisting of a textbox and some additional logic.

I add 2 of those webuser control on an asp.net form, one for each
value.
added as well ON THE FORM (and not in the user control) are a button
(Add) and a label to display the result
Now, i run it ... enter 2 values, press Add and the result is
displayed in the label ... easy.

But what i want now is that when I change one of the values in one of
the textboxes in the user control (during 'onkeypress' in javascript)
is that the text in the label control is cleared.
for this to happen, I can not just implement it in the onkeypress of
the textbox, since the label control is not part of the user control
you see?

so what I need, I think, is to raise some event in onkeypress (in the
webuser control) and implement the event handler in the host form but
whithout a postback to the server !

any ideas?

Chris
Jul 22 '08 #7
Christian Cambier wrote:
that is to set the text of a control Ok, but my situation is a little
more complicated than that ... allow me to explain what I really try
to implement.
Why doesn't anybody ever start there, instead of asking for something
that they think that they should use? ;)
I am creating a simple calculator to add 2 values.
For the user to enter a value, I have created a web user control
consisting of a textbox and some additional logic.

I add 2 of those webuser control on an asp.net form, one for each
value.
added as well ON THE FORM (and not in the user control) are a button
(Add) and a label to display the result
Now, i run it ... enter 2 values, press Add and the result is
displayed in the label ... easy.

But what i want now is that when I change one of the values in one of
the textboxes in the user control (during 'onkeypress' in javascript)
is that the text in the label control is cleared.
for this to happen, I can not just implement it in the onkeypress of
the textbox, since the label control is not part of the user control
you see?

so what I need, I think, is to raise some event in onkeypress (in the
webuser control) and implement the event handler in the host form but
whithout a postback to the server !

any ideas?

Chris
The browser doesn't know anything at all about user controls. When the
code arrives at the browser, it's just a plain web page. So there is
nothing keeping you from accessing the element rendered by the Label
control from a client event in an element rendered by a control in the
user control.

--
Göran Andersson
_____
http://www.guffa.com
Jul 22 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: The Mess | last post by:
I am working in VB5. How do you mimmick Visual Basic's putting an Index argument at the front of the variables passed to an event when making your own control? This sounds kind of confusing so...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
7
by: Colin Young | last post by:
I have a UserControl that contains a calendar control. The calendar is not raising events (month navigation, date selections, etc.). I've checked that the OnSelectionChanged event has a handler...
0
by: Greg Park | last post by:
I have many user controls loading into a web page using Page.LoadControl However, I'm unable to figure out how to raise an event when a button is click or a check box is checked. I can have...
0
by: Joe Campbell | last post by:
I am encountering a problem raising WMI events from an asp.net application. The error received (as captured in the event log) is as follows: System.Runtime.InteropServices.COMException...
5
by: snesbit | last post by:
If a screen is made up of several user controls and those user controls contain various packaged or standard controls such as a grid, how do you raise both standard and custom events from the user...
4
by: Dave A | last post by:
I am developing a somewhat complex component at the moment and coincidently I am also reading the Framework Design Guidelines book. After reading the section about event raising I have re-written...
2
by: Gman | last post by:
Hi, I have created a usercontrol, a grid control essentially. Within it I have a class: clsGridRecord. I have coded the events such that when a user clicks on the grid, say, the events occur on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.