D
Dave
hi all,
I am looking for an example for setting/getting a user control's properties
using a code behind page instead of <script></script> tags embedded in the
..aspx page.
There seems to be millions of examples using embedded code but none actually
showing how to do it in a code behind.
for example: say there is a user control called "catsplash.ascx" containing
a simple image tag:
<asp:Image id="imgCat1" runat="server" ImageAlign="Left"></asp:Image>
so far, I have a code behind file for the control called "catsplash.ascx.vb"
Public Class CatSplash
Inherits System.Web.UI.UserControl
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents imgCat1 As System.Web.UI.WebControls.Image
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub
Private sImageURL1 As String
Public Property imageurl1() As String
Get
Return sImageURL1
End Get
Set(ByVal Value As String)
sImageURL1 = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
imgCat1.ImageUrl = sImageURL1
End Sub
End Class
Then, in the .aspx page containing the control (category.aspx), I have
<%@ Page CodeBehind="category.aspx.vb" Language="vb" AutoEventWireup="false"
Inherits="BVCommerce.category" %>
<%@ Register TagPrefix="uc1" TagName="CatSplash"
Src="controls/CatSplash.ascx" %>
....
<uc1:catsplash id="CatSplash1" runat="server"
Visible="False"></uc1:catsplash>
....
how do I reference the control in the codebehind? (category.aspx.vb)
for example, I just want to set the image url to something else.
but the following does not work in the code behind:
CatSplash.imageurl1 = "images/mycategoryheader.jpg"
I am not sure how I need to reference this - "CatSplash" is the name of the
class as you can see above and I have a public property called "imageurl1",
yet it does not work as expected. (in the books, they reference it by the
id of the control inside a <script> tag, but this won't work either in a
code behind)
What am I doing wrong here?
TIA,
Dave
I am looking for an example for setting/getting a user control's properties
using a code behind page instead of <script></script> tags embedded in the
..aspx page.
There seems to be millions of examples using embedded code but none actually
showing how to do it in a code behind.
for example: say there is a user control called "catsplash.ascx" containing
a simple image tag:
<asp:Image id="imgCat1" runat="server" ImageAlign="Left"></asp:Image>
so far, I have a code behind file for the control called "catsplash.ascx.vb"
Public Class CatSplash
Inherits System.Web.UI.UserControl
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents imgCat1 As System.Web.UI.WebControls.Image
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub
Private sImageURL1 As String
Public Property imageurl1() As String
Get
Return sImageURL1
End Get
Set(ByVal Value As String)
sImageURL1 = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
imgCat1.ImageUrl = sImageURL1
End Sub
End Class
Then, in the .aspx page containing the control (category.aspx), I have
<%@ Page CodeBehind="category.aspx.vb" Language="vb" AutoEventWireup="false"
Inherits="BVCommerce.category" %>
<%@ Register TagPrefix="uc1" TagName="CatSplash"
Src="controls/CatSplash.ascx" %>
....
<uc1:catsplash id="CatSplash1" runat="server"
Visible="False"></uc1:catsplash>
....
how do I reference the control in the codebehind? (category.aspx.vb)
for example, I just want to set the image url to something else.
but the following does not work in the code behind:
CatSplash.imageurl1 = "images/mycategoryheader.jpg"
I am not sure how I need to reference this - "CatSplash" is the name of the
class as you can see above and I have a public property called "imageurl1",
yet it does not work as expected. (in the books, they reference it by the
id of the control inside a <script> tag, but this won't work either in a
code behind)
What am I doing wrong here?
TIA,
Dave