最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Add JavaScript to NewForm for SPList in SharePoint - Stack Overflow

programmeradmin4浏览0评论

I have a SPList in SharePoint that I want to edit the NewForm.aspx for. I want to add a few JavaScripts as WebParts to the form programmatically.

How do I do that?

Thanks for helping.

I have a SPList in SharePoint that I want to edit the NewForm.aspx for. I want to add a few JavaScripts as WebParts to the form programmatically.

How do I do that?

Thanks for helping.

Share Improve this question asked Apr 27, 2012 at 13:05 carruwcarruw 3595 gold badges10 silver badges22 bronze badges 2
  • 1 Well, I have my SPContentType and tried to use the "NewFormUrl" but I cannot find the newform.aspx on my server. I simply don't know where to look. – carruw Commented Apr 27, 2012 at 13:13
  • @JamesMontagne: Seems like a fair question to me, the guy clearly is inexperienced. – Brian Scott Commented Apr 27, 2012 at 13:14
Add a ment  | 

2 Answers 2

Reset to default 2

Open the list in SharePoint designer in the "lists and libraries" section. In the list designer view you will see a list of forms associated with the list, there will generally be a "NewForm.aspx" form listed. Right click this and then select "Edit File in Advanced Mode" to expose the ASP .Net / HTML markup used for the form.

Now, add your custom block within the page markup. I'd generally remend that you find the asp:content element with id 'PlaceHolderMain'. Add your script as the first element immediately after the content placeholder element opens like:

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type='text/javascript' language='javascript'>
$(document).ready(function(e) { alert('my custom script has loaded'); });
</script>
..
.. Existing markup
..
</asp:Content>

My example above assumes you have jQuery present in your masterpage to display the message after the form has fully loaded.

If you don't want to (or can't) use SharePoint Designer you can put

?ToolpaneView=2

on the end of the URL to open the View/Edit/new form in design mode in the browser.

http://blog.pentalogic/2010/07/how-to-edit-list-forms-sharepoint-2010/

发布评论

评论列表(0)

  1. 暂无评论