Problem with User Control...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone please tell me why when I refer to a Sub in my User Control I
get the following error...

Error:..
Reference to a non-shared member requires an object reference

For some reason I can't find out why I am unable to refer to the following
sub...

Would be grateful for any help...


ASPX page...

cpncms_v1.UploadCnt.UploadData()

ASCX Page...

Sub UploadData()
'Dim ImageFile As System.Web.UI.HtmlControls.HtmlInputFile
Dim imgstream As Stream = ImageFile.PostedFile.InputStream
Dim imgdata(ImageFile.PostedFile.ContentLength) As Byte
imgstream.Read(imgdata, 0, ImageFile.PostedFile.ContentLength)


Dim MyConn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("fileUpload", MyConn)
cmd.CommandType = CommandType.StoredProcedure

Dim titleparam As New SqlParameter("@fileTitle", SqlDbType.NVarChar,
255)
Dim descriptionparam As New SqlParameter("@fileDescription",
SqlDbType.NVarChar, 255)
Dim Ownerparam As New SqlParameter("@fileOwner", SqlDbType.NVarChar,
255)
Dim Officeparam As New SqlParameter("@officeID", SqlDbType.Int)
Dim typeparam As New SqlParameter("@fileType", SqlDbType.NVarChar,
100)
Dim dataparam As New SqlParameter("@fileData", SqlDbType.Image)

'Dim ImageTitle As System.Web.UI.WebControls.TextBox
'Dim fldOwner As System.Web.UI.WebControls.TextBox
'Dim fldDescription As System.Web.UI.WebControls.TextBox
'Dim ddlOffice As System.Web.UI.WebControls.DropDownList

titleparam.Value = ImageTitle.Text
descriptionparam.Value = fldDescription.Text
Ownerparam.Value = fldOwner.Text
Officeparam.Value = ddlOffice.SelectedIndex
typeparam.Value = ImageFile.PostedFile.ContentType
dataparam.Value = imgdata

cmd.Parameters.Add(titleparam)
cmd.Parameters.Add(descriptionparam)
cmd.Parameters.Add(Ownerparam)
cmd.Parameters.Add(Officeparam)
cmd.Parameters.Add(typeparam)
cmd.Parameters.Add(dataparam)

MyConn.Open()
cmd.ExecuteNonQuery()
MyConn.Close()
End Sub
 
Hi Tim,

You have to create an instance of the class first so that you can reference
the object.

if you want to referenece the object like you are doing it at the moment you
have to make it a shared method and then you will not need an instance
variable in order to referenece it.

HTH

cheers

martin.
 
Thanks for the reply!

I'm kind of new to this so I was wondering if you could explain how I create
an instance of the class so I can reference it!

Thanks...
 
Back
Top