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!

passing a value

Status
Not open for further replies.

zma

Programmer
May 30, 2006
25
US
I am passing a value from an aspx to an ascx like this. It is inside a gridview.
----------------------------------------------
<prefix1:name1 TestData='<%#eval("demid")%>' ID="ctrlTester1" runat="server" />
----------------------------------------------
At the top of the ascx is this
----------------------------------------------
Public x As Integer
Public Property testdata() As integer
Get
Return x
End Get
Set(ByVal value As integer)
x=value
Label1.Text = x 'LABEL1 SHOWS THE RIGHT VALUE
End Set
End Property
-----------------------------------------------
I am trying to use x in a query like this. It runs when the page loads.
-----------------------------------------------
Dim connection1 As SqlConnection = New SqlConnection()
connection1.Open()
Dim q As String = "select * from dems where demid=" & x.ToString()
Response.Write(q) ' ALWAYS HAS WHERE DEMID=0 HERE
Dim command1 As SqlCommand = New SqlCommand(q, connection1)
Dim reader1 As SqlDataReader = command1.ExecuteReader()

-----------------------------------------------
q keeps displaying as 'select * from dems where demid=0' but should not.
Demid is never 0. No rows are found.
The right value of x gets printed to a label so the value of x is there.

How do I get x to be the value of demid in the query?
 
most likely it's because of the order of events. the page load is fired before the databind has occured.

either select the data right after setting the property value
Code:
public int Id
{
   set
   {
       id = value;
       Control.DataBind();
   }
}
you could also expose a data bind function/event and have the page bind the control after the value is set.

I would recommend not using the page load event in the ascx to bind the data since this event has no knowledge of if/when the variable is set.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top