Hello,
I have populated a web form with dynamically created radiobuttons in
a table. I wnat some of the radio buttons to fire events when their
..CheckChanged property has changed.
I understand and was told this can be done with events and delegates. But my
code would
not compile. Here is what i did.
public delegate void specialRadioEve ntHandler(objec t sender, EventArgs e);
....
....
....
private void BuildMyDialog()
{
//Dynamically creating my table . Function called in
page_Load(IsPos tBack==false)
....
....
....
RadioButton rb = new RadioButton();
if (RadioMeetMycod nition)
{
rb.AutoPostBack = true;
rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething );
}
public voidDoSomething (object sender, EventArgs e)
{
//Only for testing purpose.
string teststring = "oi";
Response.Write( teststring);
}
.......
.......
.....
I'am i doing something wrong?
Thanks... 7 1306
you have to create the radio button even in post back. So remove IsPostBack
line.
If you dont create the control, asp.net runtime will not have the control
and cant handle the event that it supposed to do.
Av.
"bredal Jensen" <br******@jense n.dk> wrote in message
news:uh******** ******@TK2MSFTN GP12.phx.gbl... Hello, I have populated a web form with dynamically created radiobuttons in a table. I wnat some of the radio buttons to fire events when their .CheckChanged property has changed. I understand and was told this can be done with events and delegates. But my code would not compile. Here is what i did.
public delegate void specialRadioEve ntHandler(objec t sender, EventArgs e);
...
...
...
private void BuildMyDialog()
{
//Dynamically creating my table . Function called in page_Load(IsPos tBack==false)
...
...
...
RadioButton rb = new RadioButton();
if (RadioMeetMycod nition)
{
rb.AutoPostBack = true;
rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething );
} public voidDoSomething (object sender, EventArgs e)
{
//Only for testing purpose.
string teststring = "oi";
Response.Write( teststring);
}
......
......
.... I'am i doing something wrong?
Thanks...
I do in fact create the control when the very first time the
page loads . (IsPostBack==fa lse ) in the Page_load event.
"avnrao" <av*@newsgroups .com> wrote in message
news:uG******** *****@TK2MSFTNG P09.phx.gbl... you have to create the radio button even in post back. So remove
IsPostBack line.
If you dont create the control, asp.net runtime will not have the control and cant handle the event that it supposed to do.
Av.
"bredal Jensen" <br******@jense n.dk> wrote in message news:uh******** ******@TK2MSFTN GP12.phx.gbl... Hello, I have populated a web form with dynamically created radiobuttons in a table. I wnat some of the radio buttons to fire events when their .CheckChanged property has changed. I understand and was told this can be done with events and delegates.
But my code would not compile. Here is what i did.
public delegate void specialRadioEve ntHandler(objec t sender, EventArgs
e); ...
...
...
private void BuildMyDialog()
{
//Dynamically creating my table . Function called in page_Load(IsPos tBack==false)
...
...
...
RadioButton rb = new RadioButton();
if (RadioMeetMycod nition)
{
rb.AutoPostBack = true;
rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething );
} public voidDoSomething (object sender, EventArgs e)
{
//Only for testing purpose.
string teststring = "oi";
Response.Write( teststring);
}
......
......
.... I'am i doing something wrong?
Thanks...
then it should be working. are you concerned about not seeing your
teststring (OI).
put Response.End() after Response.Write
Av.
"bredal Jensen" <br******@jense n.dk> wrote in message
news:e2******** *****@TK2MSFTNG P11.phx.gbl... I do in fact create the control when the very first time the page loads . (IsPostBack==fa lse ) in the Page_load event.
"avnrao" <av*@newsgroups .com> wrote in message news:uG******** *****@TK2MSFTNG P09.phx.gbl... you have to create the radio button even in post back. So remove IsPostBack line.
If you dont create the control, asp.net runtime will not have the control and cant handle the event that it supposed to do.
Av.
"bredal Jensen" <br******@jense n.dk> wrote in message news:uh******** ******@TK2MSFTN GP12.phx.gbl... > Hello, > I have populated a web form with dynamically created radiobuttons in > a table. I wnat some of the radio buttons to fire events when their > .CheckChanged property has changed. > I understand and was told this can be done with events and delegates. But > my > code would > not compile. Here is what i did. > > > > > > public delegate void specialRadioEve ntHandler(objec t sender, EventArgs e); > > ... > > ... > > ... > > > > > > private void BuildMyDialog() > > { > > //Dynamically creating my table . Function called in > page_Load(IsPos tBack==false) > > ... > > ... > > ... > > RadioButton rb = new RadioButton(); > > if (RadioMeetMycod nition) > > { > > rb.AutoPostBack = true; > > rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething ); > > } > > > > public voidDoSomething (object sender, EventArgs e) > > { > > //Only for testing purpose. > > string teststring = "oi"; > > Response.Write( teststring); > > } > > > ...... > > ...... > > .... > > > > I'am i doing something wrong? > > > > > > Thanks... > > >
I did put a breakpoint in my event handler , but the code never breaks
there... Hummmm!
"avnrao" <av*@newsgroups .com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. . then it should be working. are you concerned about not seeing your teststring (OI).
put Response.End() after Response.Write
Av. "bredal Jensen" <br******@jense n.dk> wrote in message news:e2******** *****@TK2MSFTNG P11.phx.gbl... I do in fact create the control when the very first time the page loads . (IsPostBack==fa lse ) in the Page_load event.
"avnrao" <av*@newsgroups .com> wrote in message news:uG******** *****@TK2MSFTNG P09.phx.gbl... you have to create the radio button even in post back. So remove IsPostBack line.
If you dont create the control, asp.net runtime will not have the
control and cant handle the event that it supposed to do.
Av.
"bredal Jensen" <br******@jense n.dk> wrote in message news:uh******** ******@TK2MSFTN GP12.phx.gbl... > Hello, > I have populated a web form with dynamically created radiobuttons
in > a table. I wnat some of the radio buttons to fire events when their > .CheckChanged property has changed. > I understand and was told this can be done with events and delegates. But > my > code would > not compile. Here is what i did. > > > > > > public delegate void specialRadioEve ntHandler(objec t sender,
EventArgs e); > > ... > > ... > > ... > > > > > > private void BuildMyDialog() > > { > > //Dynamically creating my table . Function called in > page_Load(IsPos tBack==false) > > ... > > ... > > ... > > RadioButton rb = new RadioButton(); > > if (RadioMeetMycod nition) > > { > > rb.AutoPostBack = true; > > rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething ); > > } > > > > public voidDoSomething (object sender, EventArgs e) > > { > > //Only for testing purpose. > > string teststring = "oi"; > > Response.Write( teststring); > > } > > > ...... > > ...... > > .... > > > > I'am i doing something wrong? > > > > > > Thanks... > > >
You have to enable viewstate on the radio button and every control
above it in the control tree for this to work. Are you turning it off
somewhere?
-Sam
"bredal Jensen" <br******@jense n.dk> wrote in message news:<uh******* *******@TK2MSFT NGP12.phx.gbl>. .. Hello, I have populated a web form with dynamically created radiobuttons in a table. I wnat some of the radio buttons to fire events when their .CheckChanged property has changed. I understand and was told this can be done with events and delegates. But my code would not compile. Here is what i did.
public delegate void specialRadioEve ntHandler(objec t sender, EventArgs e);
...
...
...
private void BuildMyDialog()
{
//Dynamically creating my table . Function called in page_Load(IsPos tBack==false)
...
...
...
RadioButton rb = new RadioButton();
if (RadioMeetMycod nition)
{
rb.AutoPostBack = true;
rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething );
} public voidDoSomething (object sender, EventArgs e)
{
//Only for testing purpose.
string teststring = "oi";
Response.Write( teststring);
}
......
......
.... I'am i doing something wrong?
Thanks...
Oops. It just occured to me what your problem might be. Do
Page.Controls.A dd(rb). If it complains about not in a Form tag then
declare a placeholder in the aspx page inside the Forms tags and do
Placholder.Cont rols.Add(rb) instead.
"bredal Jensen" <br******@jense n.dk> wrote in message news:<uh******* *******@TK2MSFT NGP12.phx.gbl>. .. Hello, I have populated a web form with dynamically created radiobuttons in a table. I wnat some of the radio buttons to fire events when their .CheckChanged property has changed. I understand and was told this can be done with events and delegates. But my code would not compile. Here is what i did.
public delegate void specialRadioEve ntHandler(objec t sender, EventArgs e);
...
...
...
private void BuildMyDialog()
{
//Dynamically creating my table . Function called in page_Load(IsPos tBack==false)
...
...
...
RadioButton rb = new RadioButton();
if (RadioMeetMycod nition)
{
rb.AutoPostBack = true;
rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething );
} public voidDoSomething (object sender, EventArgs e)
{
//Only for testing purpose.
string teststring = "oi";
Response.Write( teststring);
}
......
......
.... I'am i doing something wrong?
Thanks...
I'm already adding the controls to my table cells and i want them to
populate this dynamically created table.
I just need to know which one was clicked.
The do generate a post back, (thanks to: rb.AutoPostBack = true;) but no
events other then the OnLoad.
I need to take some action only when i know that a specific click event on
the radio button was generated.
Not just every postback event
Thanks
"Sam" <sa*******@yaho o.com> wrote in message
news:1a******** *************** **@posting.goog le.com... Oops. It just occured to me what your problem might be. Do Page.Controls.A dd(rb). If it complains about not in a Form tag then declare a placeholder in the aspx page inside the Forms tags and do Placholder.Cont rols.Add(rb) instead.
"bredal Jensen" <br******@jense n.dk> wrote in message
news:<uh******* *******@TK2MSFT NGP12.phx.gbl>. .. Hello, I have populated a web form with dynamically created radiobuttons in a table. I wnat some of the radio buttons to fire events when their .CheckChanged property has changed. I understand and was told this can be done with events and delegates.
But my code would not compile. Here is what i did.
public delegate void specialRadioEve ntHandler(objec t sender, EventArgs
e); ...
...
...
private void BuildMyDialog()
{
//Dynamically creating my table . Function called in page_Load(IsPos tBack==false)
...
...
...
RadioButton rb = new RadioButton();
if (RadioMeetMycod nition)
{
rb.AutoPostBack = true;
rb.CheckedChang ed+=new specialRadioEve ntHandler( DoSomething );
} public voidDoSomething (object sender, EventArgs e)
{
//Only for testing purpose.
string teststring = "oi";
Response.Write( teststring);
}
......
......
.... I'am i doing something wrong?
Thanks... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marty McDonald |
last post by:
It is still unclear to me why we would use events when delegates seem to do
just fine. People say that events make it so the publisher doesn't need to
know about the listeners. What does that mean? Why are events better than
delegates? Thanks
|
by: Rakesh Rajan |
last post by:
Hi,
I find that when i define a delegate, it gets derived from
MulticastDelegate, which provides all funtionality that events would provide
(like registering new handlers etc.). Then, apart from being a bit more
neater, could there have been any other reason that an 'event' keyword became
necessary in C#?
Thanks in advance,
--
|
by: LP |
last post by:
Hello!
I am still transitioning from VB.NET to C#. I undertand the basic concepts
of Delegates, more so of Events and somewhat understand AsyncCallback
methods. But I need some clarification on when to use one over another? If
anyone could provide any additional info, your comments, best practices, any
good articles, specific examples, etc.
Thank you
|
by: Chris |
last post by:
Hi,
what is the difference between using events and delegates (apart from the
syntax) ?
have a look at following (working) programs please
(you can just copy/paste and build it) :
First program uses delegates, the second events but both do inherently the
same :
|
by: Nicky Smith |
last post by:
Hello,
I'm studying a book on VB.net Win apps, and I'm reading a section on
events and delegates and raising events.
Is it just me, or is this not just subs dressed up as something else?
I mean, for one, delegates point to subs, so when you call a delegate,
why not just call the sub dierectly and not bother adding the extra
code involved adding the delegate?
| |
by: Tim |
last post by:
There are a set of clients who need to be notified of certain events. I have
used events and delegates (publisher-Subscriber model) for the
notification mechanism. All the clients register with the event publisher
and subscribe for the events that they are interested in. When a certain
event happens, the subscribers are notified about it.
I want the clients to return a value after their callback method is called.
If any of the client...
|
by: Burkhard |
last post by:
Hi,
I am new to C# (with long year experience in C++) and I am a bit confused by
the language construct of events. What is it I can do with events that I
cannot do with delegates? At the moment it seems to me that Microsoft has
developed similar functionality via two keywords. I do understand that an
event offers better encapsulation as the underlying delegate is private, but
is that all ?
--
Regards
|
by: kristian.freed |
last post by:
Hi,
I currently work in a project written fully in C# where we make
extensive use of delegates and events. We have a model where a "state",
an object holding data but not much code but which fires events when
the data changes, is often the central part. Connected to these states
are various observers that act on changes in data, by altering the
information presented to the user, executing code and so on, each
observer with its own...
|
by: raylopez99 |
last post by:
I understand delegates (static and non-static) and I agree they are
very useful, and that the "Forms" used in the Windows .NET API could
not work without them. That said, I'm curious as to how many heavy
duty pro programmers in this newsgroup have actually used a delegate
in their code, say in the last year of coding. By "use" I mean
constructed a delegate and using it in an Event Source class and an
Event Receiver class.
Interfaces...
|
by: Siegfried Heintze |
last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I
would like some clarify the difference between events and delegates. On page
156 I see a WinForms example of timer that uses the "WithEvents" and events.
There is another example on page 124 that shows how to use delegates to sort
an array.
I don't understand the difference between events and delegates. Are they
redundant features? How do I decide which to use?
...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |