Reference custom list form fields from code behind and automatically fill them with values.

Posted by Janis Veinbergs on Stack Overflow See other posts from Stack Overflow or by Janis Veinbergs
Published on 2009-07-13T11:37:25Z Indexed on 2010/06/16 5:52 UTC
Read the original article Hit count: 570

Filed under:
|
|

Hello.

I`v made my custom NewForm.aspx for my list and I want to add some custom code to it. So I inherit that form from my own class:

public class MyCustomNewForm : Microsoft.SharePoint.WebPartPages.WebPartPage

Now I want to reference some of available fields to automatically fill them for user. (Javascript won't help here as I have to get some data from other lists).

But I have no idea how do I reference these fields from codebehind files.

The code for control field is written (well, it was generated by Sharepoint Designer when using command Insert > SharePoint Controls > Custom List Form...) in .aspx page like this:

<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="New" FieldName="Title" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}"/>

When looking at id at runtime, it is insanely long

alt text

So how do i reference fields, so I could set Text property on them in my codebehind file?

© Stack Overflow or respective owner

Related posts about sharepoint

Related posts about forms