473,386 Members | 2,129 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,386 software developers and data experts.

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 2656
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Patrick | last post by:
Hello I have the following problem. I have an aspx Page. This page contains an ASP-Table Object. So in that table, I have a linkbutton. So, I can't edit the event of that button trough the...
2
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the...
2
by: JezB | last post by:
I'm adding WebControl objects to a Page dynamically on Page_Load, but I'm having trouble attaching events to these. For example, adding an image button :- ImageButton nb = new ImageButton();...
1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
3
by: Bruce Wood | last post by:
Maybe I'm going nuts, but I was so sure that adding the same method more than once to a delegate would result in only one entry on the delegate's call list: this.UpdateEnd += new...
5
by: Steve Moreno | last post by:
Hi all, I've got a web form that I've written code to create an array of DropDownList controls on the page depending on how many records are pulled back. The code to create the controls is...
11
by: Neo Geshel | last post by:
Greetings. Hopefully someone will be able to untie this Gordian Knot I have found myself bound up in. I am trying to add a submit button dynamically to a PlaceHolder. This button will help...
4
by: Dinsdale | last post by:
I'm looking at adding scheduling features to an application and I wanted to ask the community about any experience with scheduling components, either open source like from code project or from a...
6
nomad
by: nomad | last post by:
Hello Everyone: I'm having troubles with some coding and Idon't know where it is. I have delevopled a calender where the client can add events to a day. The code worked perfect on my computer but...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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: 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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.