"Page.Clientscript" does not compile in assembly,

  • Thread starter Thread starter Jon Paal
  • Start date Start date
J

Jon Paal

"Page.Clientscript" does not compile in assembly, with the error message "Reference to a non-shared member requires an object
reference". ...

what reference is it looking for ??????


class class1
public sub showimg()
Dim Response As HttpResponse = HttpContext.Current.Response
Dim theImage As New object
theImage.ImageUrl = Page.ClientScript.RegisterStartupScript.GetWebResourceUrl(Me.GetType(), "img.gif")
response.write( "<img src=""" & theImage & """>")
end sub
end class
 
Jon said:
"Page.Clientscript" does not compile in assembly, with the error
message "Reference to a non-shared member requires an object
reference". ...
what reference is it looking for ??????


class class1
public sub showimg()
Dim Response As HttpResponse = HttpContext.Current.Response
Dim theImage As New object
theImage.ImageUrl =
Page.ClientScript.RegisterStartupScript.GetWebResourceUrl(Me.GetType(),
"img.gif") response.write( "<img src=""" & theImage & """>") end sub
end class

Replace
theImage.ImageUrl =
Page.ClientScript.RegisterStartupScript.GetWebResourceUrl(Me.GetType(),
"img.gif")
with
theImage.ImageUrl = Page.ClientScript.RegisterStartupScript(Me.GetType(),
"img.gif")

RegisterStartupScript is a function, not a property.
 
I still get the same error message ...

class class1
public sub showimg()
Dim Response As HttpResponse = HttpContext.Current.Response
Dim theImage As New object
theImage.ImageUrl = Page.ClientScript.RegisterStartupScript(Me.GetType(), "img.gif")
response.write( "<img src=""" & theImage & """>")
end sub
end class
 
"Page.Clientscript" does not compile in assembly, with the error message
"Reference to a non-shared member requires an object reference". ...

what reference is it looking for ??????

class class1
public sub showimg()
Dim Response As HttpResponse = HttpContext.Current.Response
Dim theImage As New object
theImage.ImageUrl =
Page.ClientScript.RegisterStartupScript.GetWebResourceUrl(Me.GetType(),
"img.gif")
response.write( "<img src=""" & theImage & """>")
end sub
end class

Apparently this code is not in an aspx/ascx codebehind, but in an
"external" class. "Page" is not some system-wide global variable, but a
property of the Control class. That is why you can use it there, but
not here. You need to pass a reference to your page to this function.

public sub showimg(MyPage as System.Web.UI.Page)
....
theImage.ImageUrl = MyPage.Register....

Remark 2: I don't know VB that well, but if you declare "theImage" as a
plain "object", does it recognise properties like "ImageUrl" (which is
not a property of "object")?

Remark 3: I'm not sure the line "<img src=""" & theImage & """>" will
give the required result. Why not directly put the URL you get from the
WebResource here?

Hans Kesting
 
Apparently this code is not in an aspx/ascx codebehind, but in an "external" class.

yes this is an assembly class

"Page" is not some system-wide global variable,..

I inherited the page class and now it compiles
Remark 2: I don't know VB that well, but if you declare "theImage" as a plain "object", does it recognise properties like
"ImageUrl" (which is not a property of "object")?

not sure ...

Remark 3: I'm not sure the line "<img src=""" & theImage & """>" will give the required result. Why not directly put the URL you
get from the WebResource here?


I don't know the url of the image as it is stored in the assembly with a unique identifier url
 
Back
Top