自定义NewForm.aspx页面,如何把值传到list中去
我用vs2008 vsewss 建了个listDefinition ,然后修改NewForm.aspx
首先我把<WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main" />删掉
因为原先这个页面只有一个“标题”,我想改变这个页面
然后我建了一个button,想把页面的值传到List中去,但是提交好后没反应这是为什么?
源代码:(NewForm.aspx)
<%@ Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><script runat="server"> protected string _returnUrl = null; public string ReturnUrl { get { if (_returnUrl != null) return _returnUrl; return (Request.QueryString["Source"]); } set { _returnUrl = value; } } /// <summary> /// Go to specified url /// </summary> protected void GoToUrl(string url) { try { Response.Redirect(url, true); } catch (System.Threading.ThreadAbortException) { } } public void submit_Click(object sender, EventArgs e) { //TextBox title = (TextBox)Page.FindControl("title"); //if (SetValues(title.ToString())) if (SetValues("aaaaa")) GoToUrl(ReturnUrl); } protected bool SetValues(string title) { SPWeb web = SPContext.Current.Web; web.AllowUnsafeUpdates = true; SPListItem item = SPContext.Current.Item as SPListItem; if (item != null) { if (!Page.IsValid) return false; item["title"] = title; item.Update(); } //或者:两个方法都试过都不行 //SPContentType ctype = web.ContentTypes["shouwenType"];这个是我用vs2008建的自定义内容类型 //if (ctype != null) //{ // SPList list = SPContext.Current.List; // if (list != null) //{ // SPListItem item = list.Items.Add(); //if (item != null) //{ //if (!Page.IsValid) return false; //item["title"] = txtTitle.Text; //item.Update(); //} //} return true; }</script><asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server"> <SharePoint:ListFormPageTitle runat="server"/></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server"> <SharePoint:ListProperty Property="LinkTitle" runat="server" id="ID_LinkTitle"/>: <SharePoint:ListItemProperty id="ID_ItemProperty" MaxLength=40 runat="server"/></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server"> <IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"/><asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"><table cellpadding=0 cellspacing=0 id="onetIDListForm"> <tr> <td> <asp:TextBox ID="title" runat="server"></asp:TextBox> <asp:Button ID="submit" runat="server" Text="提交" OnClick="submit_Click" /> <IMG SRC="/_layouts/images/blank.gif" width=590 height=1 alt=""> </td> </tr></table></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderTitleLeftBorder" runat="server"><table cellpadding=0 height=100% width=100% cellspacing=0> <tr><td class="ms-areaseparatorleft"><IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></td></tr></table></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server"><script id="onetidPageTitleAreaFrameScript"> document.getElementById("onetidPageTitleAreaFrame").className="ms-areaseparator";</script></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderBodyAreaClass" runat="server"><style type="text/css">.ms-bodyareaframe { padding: 8px; border: none;}</style></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderBodyLeftBorder" runat="server"><div class='ms-areaseparatorleft'><IMG SRC="/_layouts/images/blank.gif" width=8 height=100% alt=""></div></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderTitleRightMargin" runat="server"><div class='ms-areaseparatorright'><IMG SRC="/_layouts/images/blank.gif" width=8 height=100% alt=""></div></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderBodyRightMargin" runat="server"><div class='ms-areaseparatorright'><IMG SRC="/_layouts/images/blank.gif" width=8 height=100% alt=""></div></asp:Content><asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaSeparator" runat="server"/>
<?xml version="1.0"?><List xmlns:ows="Microsoft SharePoint" Title="shouwenList" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/shouwenList" BaseType="0" Name="shouwenList" Id="7f51ff05-814d-46da-8fb3-c142496a8677" Type="100" xmlns="http://schemas.microsoft.com/sharepoint/"> <MetaData> <ContentTypes> <ContentTypeRef ID="0x01"> <Folder TargetName="Item"/> </ContentTypeRef> <ContentTypeRef ID="0x0120"/> </ContentTypes> <Fields> </Fields> <Views> ........ </Views> <Forms> <Form Type="DisplayForm" Url="DispForm.aspx" WebPartZoneID="Main"/> <Form Type="EditForm" Url="EditForm.aspx" WebPartZoneID="Main"/> <Form Type="NewForm" Url="NewForm.aspx"/> </Forms> </MetaData></List>