embeding Javascript src attribute in User control

  • Thread starter New Asp.net developer
  • Start date
N

New Asp.net developer

I have a System.Web.UI.UserControl as custom control. I
have a javascript block for user control. The problem is
I want to bring src attribute from outside as property or
other method.

e.g <script language="JavaScript"
src="Scripts/filename.js"></script>

When I register this control (drop control) on aspx page
different than current folder in other words, when I have
aspx page few level down asp.net application the src
attribute does not work. Any ideas.... I am really new
to asp.net
 
V

Victor Garcia Aprea

Hi,

I'm not sure I'm following your explanation. You want to add a "Src"
property to your usercontrol? What do you mean by the 'src' attribute not
working? Please provide some more details in order to help the guessing
game.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
 
R

Ryan Healey

Hi - You need to make the scr attribute a property of your user control and
use a private variable within the control which gets the value of the
property. You can then control the src attribute from the page calling the
control for example...

Your page ...

<mycontrol:control MySrcProperty="../../anywhere.js" runat="server"/>

Within UserControl...

Then in your user control get the MySrcProperty with something like...

Dim m_MySrcProperty As String = "defaultvalue.js"

Public Property MySrcProperty() As String
Get
Return m_MySrcProperty
End Get
Set(ByVal Value As String)
m_MySrcProperty = Value
End Set
End Property

Hope this helps you along the way and i've understood you correctly :)

Kindest Regards,

Ryan Healey

InstantASP Ltd - ASP.NET Collaboration & Support Tools
 
N

NH

Hi There,

If you're looking to creating a custom control, have a look at ResolveURL
method . Will return url relative to the root.

eg... string url = ResolveUrl("~/scripts/filename.js")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top