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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass variable from aspx page to user control

Status
Not open for further replies.

mutidjo

MIS
Nov 29, 2001
27
US
I've seen ways to pass a variable from a user control to an aspx page. However I need to do the opposite. I am programming in VB.

Basically, I have a host form which has a datagrid. I want the user to select some items in the datagrid by clicking on the checkboxes, then I want the id of the item they selected to be passed on to the user control. I have a Delete hyperlink on the user control. When the user clicks on the Delete byperlink, the deletion of the selected item occurs based on the item's id on the host form.

thanks for any help in advance.
 
You set up a property, and pass the value in via that property. Keep in mind that userControls, aspx pages, anything and everything in ASP.NET are, at the root, classes of the main application.

Therefore, how would you send a value to a class? Via a property. And that's exactly how you do it with a user control.

private mvarsomevar
public property somevar as object
get
return mvarsomevar
end get
set(value as object)
mvarsomevar = value
end set
end property

and from the outside declaratively:
<muc:myUserControl runat=server id=muc somevar=somevalue />

or programmatically:
dim muc as myuc
muc = loadcontrol(&quot;userControls/myuc.ascx&quot;)
muc.somevar = someValue


and so on...

:)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top