Home All Groups Group Topic Archive Search About

"Page.Clientscript" does not compile in assembly,

Author
10 Sep 2006 6:21 PM
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

Author
10 Sep 2006 6:27 PM
Riki
Jon Paal wrote:
Show quote
> "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.

--

Riki
Author
10 Sep 2006 6:51 PM
Jon Paal
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
Author
11 Sep 2006 7:31 AM
Hans Kesting
Show quote
> "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

AddThis Social Bookmark Button