Newbie: OnClick reassignment

T

Ted Singh

Is there anyway to dynamically change the OnClick method for an object? I
keep getting a BC30390 compilation error.

Essentially what I'm trying to do is dynamically put up buttons on the page
w/o putting <asp:ImageButton ...> in the html. Is there a better way?

Here is a snippet of my code:

<script ...>
sub Page_Load(Sender as Object, e as EventArgs)
dim i as integer
dim myButton as ImageButton

for i = 1 to 3
myButton = New ImageButton()
myButton.ID = "Button" & i
myButton.CssClass = "button" & i
myButton.OnClick="btnOnClick" & i
myForm.Controls.Add(myButton)
next

sub btnOnClick1(Sender as Object, e as EventArgs)
'do something really cool
end sub
</script>

<html>
...
</html>
 
B

Bob Barrows [MVP]

Ted said:
Is there anyway to dynamically change the OnClick method for an
object? I keep getting a BC30390 compilation error.

Essentially what I'm trying to do is dynamically put up buttons on
the page w/o putting <asp:ImageButton ...> in the html. Is there a
better way?

Here is a snippet of my code:

<script ...>
sub Page_Load(Sender as Object, e as EventArgs)
dim i as integer
dim myButton as ImageButton

for i = 1 to 3
myButton = New ImageButton()
myButton.ID = "Button" & i
myButton.CssClass = "button" & i
myButton.OnClick="btnOnClick" & i
myForm.Controls.Add(myButton)
next

sub btnOnClick1(Sender as Object, e as EventArgs)
'do something really cool
end sub
</script>

<html>
...
</html>

This question would be better likely to get an answer on
..scriptiong.vbscript or one of the groups with "dhtml" in their names. It
has nothing to do with ASP, which is server-side technology. For future
reference, if you can reproduce your problem with a .htm file, you are not
having an ASP problem.

To answer your question, you need to use GetRef() to assign an event handler
to an object with vbscript. Like this:

myButton.OnClick= GetRef("btnOnClick" & i)

Please follow up in a client-side script newsgroup.

Bob Barrows
 
M

Mike Brind

Ted said:
Is there anyway to dynamically change the OnClick method for an object? I
keep getting a BC30390 compilation error.

Essentially what I'm trying to do is dynamically put up buttons on the page
w/o putting <asp:ImageButton ...> in the html. Is there a better way?

Here is a snippet of my code:

<script ...>
sub Page_Load(Sender as Object, e as EventArgs)
dim i as integer
dim myButton as ImageButton

for i = 1 to 3
myButton = New ImageButton()
myButton.ID = "Button" & i
myButton.CssClass = "button" & i
myButton.OnClick="btnOnClick" & i
myForm.Controls.Add(myButton)
next

sub btnOnClick1(Sender as Object, e as EventArgs)
'do something really cool
end sub
</script>

<html>
...
</html>
This is a dotnet question, not a classic ASP question. You are more
likely to get help from the clever bods in a dotnet news group.
 
B

Bob Barrows [MVP]

Mike said:
This is a dotnet question, not a classic ASP question. You are more
likely to get help from the clever bods in a dotnet news group.

Of course! I missed the "as ..." parts. This is vb.net, not vbscript. D'oh!

Bob Barrows
 
T

Ted

Sorry for posting in the wrong place ... I'll post in VB.NET or .NET in the
future.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,431
Latest member
ElyseG3173

Latest Threads

Top