Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass parameters through asp button onclick?

Status
Not open for further replies.

jonofnewport

Technical User
Sep 8, 2006
3
0
0
US
Hello,

I am developing an asp.net program to interact with an access database. I'm very new and just learning. Coding in VB.



I've learned how to call a procedure such as:

sub orderByModel(s As Object, e As EventArgs) ... end sub

by clicking on a button in a form such as:

<asp:button text="Model" onclick="orderByModel" runat="server"/>



Now what I want to do is call a "function" (with arguments), such as:

function orderBy(para as string) ... end function

by clicking on a button, kind of like this (though not proper code):

<asp:button text="Model" onclick="orderBy("Model")" runat="server"/>



Can it be done?

Thanks!
 
HI,

Call your function inside your sub

sub orderByModel(s As Object, e As EventArgs)

orderBy(ButtonID.Text)
'or whatever you want the Function to use

end sub

function orderBy(para as string)

Do something with para

end function

Don't forget to give your button an ID

j

 
Also consider using a querystring for your code. It'll require a postback, so you'll have to handle that as well.

______________________________________________
When told, "goto hell", a programmer finds the method, not the destination as harmful.
 
Thanks for the replies.

I also found another way to do it if anyone is interested.

A button such as:

<asp:button text="Model" onclick="orderBy" runat="server"/>

can be used to call a subroutine such as

sub orderBy(s As Object, e As EventArgs)

perform operations using s.text 'In this case "Model"

end sub


works great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top