473,378 Members | 1,592 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,378 software developers and data experts.

Events and delegates.

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 specialRadioEventHandler(object sender, EventArgs e);

....

....

....

private void BuildMyDialog()

{

//Dynamically creating my table . Function called in
page_Load(IsPostBack==false)

....

....

....

RadioButton rb = new RadioButton();

if (RadioMeetMycodnition)

{

rb.AutoPostBack = true;

rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );

}

public voidDoSomething (object sender, EventArgs e)

{

//Only for testing purpose.

string teststring = "oi";

Response.Write(teststring);

}
.......

.......

.....

I'am i doing something wrong?

Thanks...

Nov 18 '05 #1
7 1294
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******@jensen.dk> wrote in message
news:uh**************@TK2MSFTNGP12.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 specialRadioEventHandler(object sender, EventArgs e);

...

...

...

private void BuildMyDialog()

{

//Dynamically creating my table . Function called in
page_Load(IsPostBack==false)

...

...

...

RadioButton rb = new RadioButton();

if (RadioMeetMycodnition)

{

rb.AutoPostBack = true;

rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );

}

public voidDoSomething (object sender, EventArgs e)

{

//Only for testing purpose.

string teststring = "oi";

Response.Write(teststring);

}
......

......

....

I'am i doing something wrong?

Thanks...

Nov 18 '05 #2

I do in fact create the control when the very first time the
page loads . (IsPostBack==false ) in the Page_load event.

"avnrao" <av*@newsgroups.com> wrote in message
news:uG*************@TK2MSFTNGP09.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******@jensen.dk> wrote in message
news:uh**************@TK2MSFTNGP12.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 specialRadioEventHandler(object sender, EventArgs e);
...

...

...

private void BuildMyDialog()

{

//Dynamically creating my table . Function called in
page_Load(IsPostBack==false)

...

...

...

RadioButton rb = new RadioButton();

if (RadioMeetMycodnition)

{

rb.AutoPostBack = true;

rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );

}

public voidDoSomething (object sender, EventArgs e)

{

//Only for testing purpose.

string teststring = "oi";

Response.Write(teststring);

}
......

......

....

I'am i doing something wrong?

Thanks...


Nov 18 '05 #3
then it should be working. are you concerned about not seeing your
teststring (OI).

put Response.End() after Response.Write

Av.
"bredal Jensen" <br******@jensen.dk> wrote in message
news:e2*************@TK2MSFTNGP11.phx.gbl...

I do in fact create the control when the very first time the
page loads . (IsPostBack==false ) in the Page_load event.

"avnrao" <av*@newsgroups.com> wrote in message
news:uG*************@TK2MSFTNGP09.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******@jensen.dk> wrote in message
news:uh**************@TK2MSFTNGP12.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 specialRadioEventHandler(object sender, EventArgs e); >
> ...
>
> ...
>
> ...
>
>
>
>
>
> private void BuildMyDialog()
>
> {
>
> //Dynamically creating my table . Function called in
> page_Load(IsPostBack==false)
>
> ...
>
> ...
>
> ...
>
> RadioButton rb = new RadioButton();
>
> if (RadioMeetMycodnition)
>
> {
>
> rb.AutoPostBack = true;
>
> rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );
>
> }
>
>
>
> public voidDoSomething (object sender, EventArgs e)
>
> {
>
> //Only for testing purpose.
>
> string teststring = "oi";
>
> Response.Write(teststring);
>
> }
>
>
> ......
>
> ......
>
> ....
>
>
>
> I'am i doing something wrong?
>
>
>
>
>
> Thanks...
>
>
>



Nov 18 '05 #4
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***************@TK2MSFTNGP10.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******@jensen.dk> wrote in message
news:e2*************@TK2MSFTNGP11.phx.gbl...

I do in fact create the control when the very first time the
page loads . (IsPostBack==false ) in the Page_load event.

"avnrao" <av*@newsgroups.com> wrote in message
news:uG*************@TK2MSFTNGP09.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******@jensen.dk> wrote in message
news:uh**************@TK2MSFTNGP12.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 specialRadioEventHandler(object sender,
EventArgs e);
>
> ...
>
> ...
>
> ...
>
>
>
>
>
> private void BuildMyDialog()
>
> {
>
> //Dynamically creating my table . Function called in
> page_Load(IsPostBack==false)
>
> ...
>
> ...
>
> ...
>
> RadioButton rb = new RadioButton();
>
> if (RadioMeetMycodnition)
>
> {
>
> rb.AutoPostBack = true;
>
> rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );
>
> }
>
>
>
> public voidDoSomething (object sender, EventArgs e)
>
> {
>
> //Only for testing purpose.
>
> string teststring = "oi";
>
> Response.Write(teststring);
>
> }
>
>
> ......
>
> ......
>
> ....
>
>
>
> I'am i doing something wrong?
>
>
>
>
>
> Thanks...
>
>
>



Nov 18 '05 #5
Sam
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******@jensen.dk> wrote in message news:<uh**************@TK2MSFTNGP12.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 specialRadioEventHandler(object sender, EventArgs e);

...

...

...

private void BuildMyDialog()

{

//Dynamically creating my table . Function called in
page_Load(IsPostBack==false)

...

...

...

RadioButton rb = new RadioButton();

if (RadioMeetMycodnition)

{

rb.AutoPostBack = true;

rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );

}

public voidDoSomething (object sender, EventArgs e)

{

//Only for testing purpose.

string teststring = "oi";

Response.Write(teststring);

}
......

......

....

I'am i doing something wrong?

Thanks...

Nov 18 '05 #6
Sam
Oops. It just occured to me what your problem might be. Do
Page.Controls.Add(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.Controls.Add(rb) instead.

"bredal Jensen" <br******@jensen.dk> wrote in message news:<uh**************@TK2MSFTNGP12.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 specialRadioEventHandler(object sender, EventArgs e);

...

...

...

private void BuildMyDialog()

{

//Dynamically creating my table . Function called in
page_Load(IsPostBack==false)

...

...

...

RadioButton rb = new RadioButton();

if (RadioMeetMycodnition)

{

rb.AutoPostBack = true;

rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );

}

public voidDoSomething (object sender, EventArgs e)

{

//Only for testing purpose.

string teststring = "oi";

Response.Write(teststring);

}
......

......

....

I'am i doing something wrong?

Thanks...

Nov 18 '05 #7

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*******@yahoo.com> wrote in message
news:1a*************************@posting.google.co m...
Oops. It just occured to me what your problem might be. Do
Page.Controls.Add(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.Controls.Add(rb) instead.

"bredal Jensen" <br******@jensen.dk> wrote in message

news:<uh**************@TK2MSFTNGP12.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 specialRadioEventHandler(object sender, EventArgs e);
...

...

...

private void BuildMyDialog()

{

//Dynamically creating my table . Function called in
page_Load(IsPostBack==false)

...

...

...

RadioButton rb = new RadioButton();

if (RadioMeetMycodnition)

{

rb.AutoPostBack = true;

rb.CheckedChanged+=new specialRadioEventHandler( DoSomething );

}

public voidDoSomething (object sender, EventArgs e)

{

//Only for testing purpose.

string teststring = "oi";

Response.Write(teststring);

}
......

......

....

I'am i doing something wrong?

Thanks...

Nov 18 '05 #8

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

Similar topics

4
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...
7
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...
4
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...
3
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...
11
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...
4
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...
30
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...
2
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...
5
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...
7
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.