469,926 Members | 1,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

adding events at run time

I'm trying to add an event handler to the on click event of an existing link
button.
here is the code:
Dim thscc As LinkButton
dWrk = dtrCal("calDate")
thscc.onClick = New EventHandler(AddressOf cc_onClick)
the .onClick is erroring out. I think i have the right idea but , ....
also if i add an event to an existing item will it need to be recreated on
each post back like a dynamicly created link button?
thanks
kes
Nov 19 '05 #1
4 2584
The code you posted doesn't refer to an existing LinkButton. You haven't
instantiated one, just created a variable of that type. You didn't mention
what error message you're getting, but my guess would be "Object reference
not set to an instance of an object."

In addition, the LinkButton must be added to the Page Controls somehow.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"WebBuilder451" <We***********@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
I'm trying to add an event handler to the on click event of an existing
link
button.
here is the code:
Dim thscc As LinkButton
dWrk = dtrCal("calDate")
thscc.onClick = New EventHandler(AddressOf cc_onClick)
the .onClick is erroring out. I think i have the right idea but , ....
also if i add an event to an existing item will it need to be recreated on
each post back like a dynamicly created link button?
thanks
kes

Nov 19 '05 #2
I suggest you use the AddHandler method.
Here's more information:
http://msdn.microsoft.com/library/de...rStatement.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"WebBuilder451" <We***********@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
I'm trying to add an event handler to the on click event of an existing
link
button.
here is the code:
Dim thscc As LinkButton
dWrk = dtrCal("calDate")
thscc.onClick = New EventHandler(AddressOf cc_onClick)
the .onClick is erroring out. I think i have the right idea but , ....
also if i add an event to an existing item will it need to be recreated on
each post back like a dynamicly created link button?
thanks
kes

Nov 19 '05 #3
thanks for replying,
(Sorry you are correct i missed a line in my posting:
thscc = FindControl("cc" & i.ToString) )

I haven't even got that far. It will not compile, but the following does
work, with the extra line.
thscc.Text = dWrk.Day.ToString
thscc.CommandName = "cc_CMD"
thscc.CommandArgument = dtrCal("calDate")
Given that i got this far how do it set the onClick event or create it?
thanks (again)
kes
"Kevin Spencer" wrote:
The code you posted doesn't refer to an existing LinkButton. You haven't
instantiated one, just created a variable of that type. You didn't mention
what error message you're getting, but my guess would be "Object reference
not set to an instance of an object."

In addition, the LinkButton must be added to the Page Controls somehow.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"WebBuilder451" <We***********@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
I'm trying to add an event handler to the on click event of an existing
link
button.
here is the code:
Dim thscc As LinkButton
dWrk = dtrCal("calDate")
thscc.onClick = New EventHandler(AddressOf cc_onClick)
the .onClick is erroring out. I think i have the right idea but , ....
also if i add an event to an existing item will it need to be recreated on
each post back like a dynamicly created link button?
thanks
kes


Nov 19 '05 #4
In that case, take Steve's advice!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"WebBuilder451" <We***********@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
thanks for replying,
(Sorry you are correct i missed a line in my posting:
thscc = FindControl("cc" & i.ToString) )

I haven't even got that far. It will not compile, but the following does
work, with the extra line.
thscc.Text = dWrk.Day.ToString
thscc.CommandName = "cc_CMD"
thscc.CommandArgument = dtrCal("calDate")
Given that i got this far how do it set the onClick event or create it?
thanks (again)
kes
"Kevin Spencer" wrote:
The code you posted doesn't refer to an existing LinkButton. You haven't
instantiated one, just created a variable of that type. You didn't
mention
what error message you're getting, but my guess would be "Object
reference
not set to an instance of an object."

In addition, the LinkButton must be added to the Page Controls somehow.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"WebBuilder451" <We***********@discussions.microsoft.com> wrote in
message
news:D7**********************************@microsof t.com...
> I'm trying to add an event handler to the on click event of an existing
> link
> button.
> here is the code:
> Dim thscc As LinkButton
> dWrk = dtrCal("calDate")
> thscc.onClick = New EventHandler(AddressOf cc_onClick)
> the .onClick is erroring out. I think i have the right idea but , ....
> also if i add an event to an existing item will it need to be recreated
> on
> each post back like a dynamicly created link button?
> thanks
> kes


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tim Marsden | last post: by
3 posts views Thread by Bruce Wood | last post: by
11 posts views Thread by Neo Geshel | last post: by
4 posts views Thread by Dinsdale | last post: by
1 post views Thread by swethak | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.