Passing Event Arguments

T

Tristan

Problem: Unable to pass an argument to a Sub Routine, Using an
<asp:button> within the templates of a DataList to execute the sub and
pass an argument to.

The datalist is filled to display a list of movies, i want the button
to submit a PK to ID a movie so that i can show the information on a
particular movie in detail.

The LinkButton code:
<asp:LinkButton id=btnShowDetails runat="server"
text='<%#Container.dataitem("Movie_Name")%>'
commandargument='<%#Container.dataitem("Movie_id")%>'
onclick='<%#LoadMovies(Container.dataitem("Movie_id"))%>' />

Public Sub LoadMovies(ByVal movRef As String, ByVal sender As
System.Object, ByVal e As System.EventArgs)
pnlMovieList.Visible = False
'using the label to test if the argument is getting through.
lblError.Text = movRef

End Sub

Any suggestions or alternatives welcome!


Regards
Tristan
 
F

Fred Sawtelle

Tristan, you need to make LoadMovies your datalist's
OnItemCommand routine. In your datalist tag, if it isn't
already there, add the
property, "OnItemCommand="LoadMovies". Change the
signature of the routine to this:

Public Sub LoadMovies(ByVal sender As System.Object,
ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs)

Get rid of the "onclick" property of your linkbutton; the
datalist is going to handle that. And you don't need to
pass your Movie_id as a parameter to the routine, because
you've already stored it in your CommandArgument. Change
your display line to:

lblError.Text = e.CommandArgument

See how far that gets you.

Fred
 

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,141
Messages
2,570,813
Members
47,357
Latest member
sitele8746

Latest Threads

Top