开发者

Register/Include javascript within RenderingTemplate

Problem description

Is it possible to register (include) javascript within RenderingTemplate? (RenderingTemplates are used to render list forms or fields) By using

<SharePoint:RenderingTemplate ID="NewRelatedListItem" runat="server">
  <Template>
    <span id="part1">
      <SharePoint:ScriptLink Name="SPFormFieldAssistant.js" Localizable="false" /> 
      ...
    </span>
    ...
  </Template>
</SharePoint:RenderingTemplate>

it couldn't be done - it didn't include script at HEAD area, but...:

Source http://img62.imageshack.us/img62/9826/ss20100324092808.png

Is something wrong with my code? Althought script IS at Layouts folder and I checked with Reflector that it uses Layouts folder if Localizable='False'.

I don't want this script to be loaded with every page, but only for forms.

Any ideas on how this could be achieved?

My idea that is not working...

My first idea was to add script programmatically with <% this.Page.ClientScript.RegisterClientScriptInclude("spff开发者_如何学编程a", "/_layouts/SPFormFieldAssistant.js") %>, but it is not working, as that code evaluation is happening in Render method and i read somwhere that you cannot register client scripts within Render method, but usually is done within PreRender method. Pity

My second idea that is still not working

I thought i would create custom UserControl named RegisterClientScript and there within overriden PreRender method i would add scripts i need with client script manager (this.Page.ClientScript...) but, as with SharePoint:ScriptLink, my control also is rendered as text! my control as text http://img693.imageshack.us/img693/3738/ss20100324115826.png

How do i overcome this and where's the catch?


Looks like you are missing the runat. Try this:

<SharePoint:ScriptLink Name="SPFormFieldAssistant.js" Localizable="false" runat="server" />


It turns out that you can directly add <script> tags to template!

<script src="/_layouts/SPFormFieldAssistant.js" type="text/javascript"></script>

Thank you for the notes however.


Sometime back I had a Similar requirement. For which I have included the script Register in the CreateChildControls method of the Field Control class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜