472,960 Members | 1,906 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 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 2835
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.