IntercareSupport
asked on
Prepopulate Sharepoint Formfield with querystring value
I am trying to pre-populate a SharePoint form field with a querystring value . What's the best way to do this?
I have seen lots of javascript examples, but I'm not much of a coder in that language. I have MOSS...Thanks.
I have seen lots of javascript examples, but I'm not much of a coder in that language. I have MOSS...Thanks.
I would go for javascript or jquery as a solution. As a c# coder learning java might not seem all that needed, but if you are planning to code for SP2010 as well I do suggest you learn to use it.
i'm not a coder either, and i was able to implement a javascript solution.
example (see comments 25498908 and 25498969):
https://www.experts-exchange.com/questions/24780905/Adding-a-page-before-NewForm-and-linking-modified-NewForm-to-a-list.html
example (see comments 25498908 and 25498969):
https://www.experts-exchange.com/questions/24780905/Adding-a-page-before-NewForm-and-linking-modified-NewForm-to-a-list.html
ASKER
It looks like you start your page with the solution I'm looking for, and are asking a few different questions.
In the screenshot below, you can see the familyid (=1) and the field that I want that value to display (obnoxious red arrow).
Now I think I can bind to a querystring variable, something like this:
<ParameterBinding Name="FamilyID" Location="QueryString(Fami lyID)" DefaultValue="@insert_data _here"/>
If I'm right, then how can I insert this query string variable into that text field?
I've attached my entire code, too.
I hope I'm not way off, here (thanks).
In the screenshot below, you can see the familyid (=1) and the field that I want that value to display (obnoxious red arrow).
Now I think I can bind to a querystring variable, something like this:
<ParameterBinding Name="FamilyID" Location="QueryString(Fami
If I'm right, then how can I insert this query string variable into that text field?
I've attached my entire code, too.
I hope I'm not way off, here (thanks).
<%@ Page masterpagefile="~masterurl/default.master" language="C#" title="|" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" meta:webpartpageexpansion="full" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SPSWC" namespace="Microsoft.SharePoint.Portal.WebControls" assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content id="Content1" runat="server" contentplaceholderid="PlaceHolderMain">
<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="Family" __markuptype="vsattributemarkup" __WebPartId="{A5E430B3-10F1-439E-AE96-9E3FE31D0926}" id="g_a5e430b3_10f1_439e_ae96_9e3fe31d0926" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
<DataSources>
<SharePoint:SPDataSource runat="server" DataSourceMode="ListItem" UseInternalName="true" selectcommand="<View><Query><Where><Eq><FieldRef Name="ContentType"/><Value Type="Text">Item</Value></Eq></Where></Query></View>" id="Family1"><SelectParameters><WebPartPages:DataFormParameter Name="ListItemId" ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0"/><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{2924625E-EB30-4703-9AA4-4FFA13696C65}"/>
</SelectParameters><DeleteParameters><WebPartPages:DataFormParameter Name="ListItemId" ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0"/><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{2924625E-EB30-4703-9AA4-4FFA13696C65}"/>
</DeleteParameters><InsertParameters><WebPartPages:DataFormParameter Name="ListItemId" ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0"/><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{2924625E-EB30-4703-9AA4-4FFA13696C65}"/>
</InsertParameters><UpdateParameters><WebPartPages:DataFormParameter Name="ListItemId" ParameterKey="ListItemId" PropertyName="ParameterValues" DefaultValue="0"/><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{2924625E-EB30-4703-9AA4-4FFA13696C65}"/>
</UpdateParameters>
</SharePoint:SPDataSource>
</DataSources>
<ParameterBindings>
<ParameterBinding Name="ListItemId" Location="QueryString(ID)" DefaultValue="0"/>
<ParameterBinding Name="ListID" Location="None" DefaultValue="{2924625E-EB30-4703-9AA4-4FFA13696C65}"/>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
</ParameterBindings>
<datafields>@Title,Title;@FamilyID,FamilyID;@Father,Adult Name;@Address,Address;@Phone,Phone;@Alternate_x0020_Phone,Alternate Phone;@SSN,SSN;@DOB,DOB;@Education_x0020_Level,Education Level;@School_x0020_Enrollment_x0020_St,School Enrollment Status;@Employed,Employed;@Employer_x0020_Name,Employer Name;@Relationship_x0020_to_x0020_Chil,Relationship to Child;@Ethnicity,Ethnicity;@Primary_x0020_Language,Primary Language;@Adult_x0020_Services,Adult Services;@Number_x0020_of_x0020_Adults,Number of Adults;@Number_x0020_of_x0020_Children,Number of Children;@Area_x0020_Type,Area Type;@Family_x0020_Income,Family Income;@Income_x0020_Source,Income Source;@Transfer_x0020_In,Transfer In;@Transfer_x0020_Out,Transfer Out;@Child_x0020_Inactive,Child Inactive;@Inactive_x0020_Start_x0020_Date,Inactive Start Date;@Inactive_x0020_End_x0020_Date,Inactive End Date;@Family_x0020_Drop_x0020_Out,Family Drop Out;@Family_x0020_Drop_x0020_Out_x002,Family Drop Out Date;@Family_x0020_Drop_x0020_Out_x0020,Family Drop Out Reason;@Child_x0020_1,Child 1;@Child_x0020_1_x0020_Name,Child 1 Name;@Child_x0020_1_x0020_DOB,Child 1 DOB;@Child_x0020_1_x0020_Age,Child 1 Age;@Child_x0020_1_x0020_Gender,Child 1 Gender;@Child_x0020_1_x0020_Birth_x0020_,Child 1 Birth Wgt;@Child_x0020_1_x0020_Ethnicity,Child 1 Ethnicity;@Child_x0020_1_x0020_Primary_x002,Child 1 Primary Language;@Child_x0020_1_x0020_Brigance_x00,Child 1 Brigance (Fall);@Child_x0020_1_x0020_Brigance_x000,Child 1 Brigance (Spring);@insert_data_here,insert_data_here;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</datafields>
<XSL>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">ListForm</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<table border="0" width="100%">
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<tr>
<td class="ms-toolbar" nowrap="">
<table>
<tr>
<td width="99%" class="ms-toolbar" nowrap=""><IMG SRC="/_layouts/images/blank.gif" width="1" height="18"/></td>
<td class="ms-toolbar" nowrap="">
<SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton1"/>
</td>
<td class="ms-separator">
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text>
</td>
<td class="ms-toolbar" nowrap="" align="right">
<SharePoint:GoBackButton runat="server" ControlMode="Edit" id="gobackbutton1"/>
</td>
</tr>
</table>
</td>
</tr>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowedit">
<xsl:with-param name="Pos" select="concat('_', position())" />
</xsl:call-template>
</xsl:for-each>
<tr>
<td class="ms-toolbar" nowrap="">
<table>
<tr>
<td class="ms-descriptiontext" nowrap="">
<SharePoint:CreatedModifiedInfo ControlMode="Edit" runat="server"/>
</td>
<td width="99%" class="ms-toolbar" nowrap=""><IMG SRC="/_layouts/images/blank.gif" width="1" height="18"/></td>
<td class="ms-toolbar" nowrap="">
<SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton2"/>
</td>
<td class="ms-separator">
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text>
</td>
<td class="ms-toolbar" nowrap="" align="right">
<SharePoint:GoBackButton runat="server" ControlMode="Edit" id="gobackbutton2"/>
</td>
</tr>
</table>
</td>
</tr>
</xsl:template>
<xsl:template name="dvt_1.rowedit">
<xsl:param name="Pos" />
<tr>
<td>
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Title<span class="ms-formvalidation"> *</span>
</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="Title" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}"/>
<SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="Title" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Adult Name</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="Edit" FieldName="Father" __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Father')}"/>
<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="Father" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Address</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="Edit" FieldName="Address" __designer:bind="{ddwrt:DataBind('u',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Address')}"/>
<SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="Address" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Phone</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff4{$Pos}" ControlMode="Edit" FieldName="Phone" __designer:bind="{ddwrt:DataBind('u',concat('ff4',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Phone')}"/>
<SharePoint:FieldDescription runat="server" id="ff4description{$Pos}" FieldName="Phone" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Alternate Phone</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff5{$Pos}" ControlMode="Edit" FieldName="Alternate_x0020_Phone" __designer:bind="{ddwrt:DataBind('u',concat('ff5',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Alternate_x0020_Phone')}"/>
<SharePoint:FieldDescription runat="server" id="ff5description{$Pos}" FieldName="Alternate_x0020_Phone" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>SSN</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff6{$Pos}" ControlMode="Edit" FieldName="SSN" __designer:bind="{ddwrt:DataBind('u',concat('ff6',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@SSN')}"/>
<SharePoint:FieldDescription runat="server" id="ff6description{$Pos}" FieldName="SSN" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>DOB</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff7{$Pos}" ControlMode="Edit" FieldName="DOB" __designer:bind="{ddwrt:DataBind('u',concat('ff7',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@DOB')}"/>
<SharePoint:FieldDescription runat="server" id="ff7description{$Pos}" FieldName="DOB" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Education Level</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff8{$Pos}" ControlMode="Edit" FieldName="Education_x0020_Level" __designer:bind="{ddwrt:DataBind('u',concat('ff8',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Education_x0020_Level')}"/>
<SharePoint:FieldDescription runat="server" id="ff8description{$Pos}" FieldName="Education_x0020_Level" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>School Enrollment Status</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff9{$Pos}" ControlMode="Edit" FieldName="School_x0020_Enrollment_x0020_St" __designer:bind="{ddwrt:DataBind('u',concat('ff9',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@School_x0020_Enrollment_x0020_St')}"/>
<SharePoint:FieldDescription runat="server" id="ff9description{$Pos}" FieldName="School_x0020_Enrollment_x0020_St" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Employed</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff10{$Pos}" ControlMode="Edit" FieldName="Employed" __designer:bind="{ddwrt:DataBind('u',concat('ff10',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Employed')}"/>
<SharePoint:FieldDescription runat="server" id="ff10description{$Pos}" FieldName="Employed" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Employer Name</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff11{$Pos}" ControlMode="Edit" FieldName="Employer_x0020_Name" __designer:bind="{ddwrt:DataBind('u',concat('ff11',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Employer_x0020_Name')}"/>
<SharePoint:FieldDescription runat="server" id="ff11description{$Pos}" FieldName="Employer_x0020_Name" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Relationship to Child</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff12{$Pos}" ControlMode="Edit" FieldName="Relationship_x0020_to_x0020_Chil" __designer:bind="{ddwrt:DataBind('u',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Relationship_x0020_to_x0020_Chil')}"/>
<SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="Relationship_x0020_to_x0020_Chil" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Ethnicity</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff13{$Pos}" ControlMode="Edit" FieldName="Ethnicity" __designer:bind="{ddwrt:DataBind('u',concat('ff13',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Ethnicity')}"/>
<SharePoint:FieldDescription runat="server" id="ff13description{$Pos}" FieldName="Ethnicity" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Primary Language</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff14{$Pos}" ControlMode="Edit" FieldName="Primary_x0020_Language" __designer:bind="{ddwrt:DataBind('u',concat('ff14',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Primary_x0020_Language')}"/>
<SharePoint:FieldDescription runat="server" id="ff14description{$Pos}" FieldName="Primary_x0020_Language" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Adult Services</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff15{$Pos}" ControlMode="Edit" FieldName="Adult_x0020_Services" __designer:bind="{ddwrt:DataBind('u',concat('ff15',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Adult_x0020_Services')}"/>
<SharePoint:FieldDescription runat="server" id="ff15description{$Pos}" FieldName="Adult_x0020_Services" ControlMode="Edit"/>
</td>
</tr>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<tr>
<td colspan="99" class="ms-vb">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
</td>
</tr>
</xsl:if><tr><td width="190px" valign="top" class="ms-formlabel">This should catch a query string variable....should be read only field.</td><td width="400px" valign="top" class="ms-formbody"><SharePoint:FormField runat="server" id="FormField1{$Pos}" ControlMode="Edit" FieldName="insert_data_here" __designer:bind="{ddwrt:DataBind('u',concat('FormField1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@insert_data_here')}" /></td></tr></table>
</td>
</tr>
</xsl:template>
</xsl:stylesheet> </XSL>
</WebPartPages:DataFormWebPart>
</asp:Content>
<asp:Content id="Content2" runat="server" contentplaceholderid="PlaceHolderPageDescription">
</asp:Content>
ee.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect!
ASKER
Hey, it worked! Thanks. My only question is this: how can I make this text box read only or not changeable?
you can do that in sharepoint designer. you change the type of field to one that is read only. i think it's called a label, but i can't recall for sure and i dont have SPD available at the moment.
ASKER
It was label. Thanks again.