locked
SPD2007 Passing a value to a newform.aspx input field RRS feed

  • Question

  • SPD2007 Passing a value to a newform.aspx input field

    I have a custom list form that has a link to a NewForm_Custom.aspx, the link looks lke this
    NewForm_Custom.aspx?UID=12345

    On NewForm_Custon.aspx I have an input field, the queston is how do I set this field to the value passed
     
    Here is the code for the field I want to set

    <td width="400px" valign="top" class="style3">
    <SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="UID" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@UID')}"/>
          <SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="UID" ControlMode="New"/>
    </td>

    Matt Pinkston

    Sunday, March 17, 2013 10:46 PM

Answers

  • Hi,

    I understand that you want to pass a value from query string to a input field on NewForm.aspx page. Here are the detailed steps:

    1.  You need to create a custom page to hold a custom list new form for the list.
    2. Add a parameter for the custom list form web part(let’s call it UID here). Set the parameter source to Query String. Set the Query string variable to UID.
    3. Convert the UID column in the custom list form to a text box.
    4. Set the text property for the text box as UID. The code would be like this : <asp:TextBox runat="server" id="ff2{$Pos}" text="{$UID}" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@UID')}"/>

    For more information, please refer to this site:

    Setting SharePoint Form Fields Using Query String Variables Without Using JavaScript: http://geekswithblogs.net/SoYouKnow/archive/2009/10/29/setting-sharepoint-form-fields-using-query-string-variables-without-using.aspx

    Thanks,

    Entan Ming

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contacttnmff@microsoft.com.


    Entan Ming
    TechNet Community Support


    Monday, March 18, 2013 1:58 AM
    Moderator
  • Hi,

    Can  you check the  NewForm.aspx form to see whether the UID query string have been passed to the new form successfully? On button click, how do  you get the UID from the URL? I think you need to use javascript behind the button to open the NewForm.aspx page with the correct UID. You can try the script below:

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

    <script type="text/javascript">

    function getUrlVars()

    {

        var vars = [], hash;

        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

        for(var i = 0; i < hashes.length; i++)

        {

            hash = hashes[i].split('=');

            vars.push(hash[0]);

            vars[hash[0]] = hash[1];

        }

        return vars;

    }

    function buttonclick ()

    {

    var string= getUrlVars()["UID"];

    alert(string);

    var string2= "URL to the new form NewForm_Custom1.aspx?UID="+string;

    window.open(string2);

    };

    </script>

    <button text="open new form" onclick="javascript:buttonclick()"></button>

    In this way, on button click on inc_userdetail.aspx, the NewForm_Custom1.aspx will be opened with UID as query string. In this way, the form field can get the correct query string.

    Thanks,

    Entan Ming

    Entan Ming
    TechNet Community Support

    Monday, March 25, 2013 10:27 AM
    Moderator

All replies

  • Hi,

    I understand that you want to pass a value from query string to a input field on NewForm.aspx page. Here are the detailed steps:

    1.  You need to create a custom page to hold a custom list new form for the list.
    2. Add a parameter for the custom list form web part(let’s call it UID here). Set the parameter source to Query String. Set the Query string variable to UID.
    3. Convert the UID column in the custom list form to a text box.
    4. Set the text property for the text box as UID. The code would be like this : <asp:TextBox runat="server" id="ff2{$Pos}" text="{$UID}" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@UID')}"/>

    For more information, please refer to this site:

    Setting SharePoint Form Fields Using Query String Variables Without Using JavaScript: http://geekswithblogs.net/SoYouKnow/archive/2009/10/29/setting-sharepoint-form-fields-using-query-string-variables-without-using.aspx

    Thanks,

    Entan Ming

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contacttnmff@microsoft.com.


    Entan Ming
    TechNet Community Support


    Monday, March 18, 2013 1:58 AM
    Moderator
  • Okay I followed the instructions but it appears something is not right somewhere as I am getting {ParmUID} in the text box on the NewForm.aspx when loaded.
     
    On my UserDetail.aspx form I have a button with the following link.
    NewForm_Custom1.aspx?UID={@ParmUID}&SOURCE=
     
    ParmUID was setup using the parmameters field, it is passed to this screen from the predecesor aspx via UID=
     
    I altered the input box on the NewForm_Custom1.aspx to a textbox and modified the code as follows
           <asp:TextBox runat="server" id="ff2{$Pos}" text="{$ParmUID}" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@UID')}" />

    NOt sure where I have messed up 


    Matt Pinkston

    Monday, March 18, 2013 6:44 PM
  • Hi,

    How to you create the ParamUID? Do you create this parameter for the custom list form web part on the NewForm_Custom1.aspx?

    If not, you need to modify the NewForm_Custom1.aspx page in SharePoint designer. Select the custom list form's task pane and add a paramter.Name the parameter as ParamUID. Set the Parameter source to Query String. Set the Query String variable to UID.

    Thanks,

    Entan Ming


    Entan Ming
    TechNet Community Support

    Tuesday, March 19, 2013 1:51 AM
    Moderator
  • Now I have three aspx files

    inc_users.aspx
    inc_userdetail.aspx
    NewForm_Custom1.aspx

    inc_users.aspx is a listing of all my users and the UID field is hyperlinked as follows:
    inc_UserDetail.aspx?ID={@ID}&amp;UID={@Title}&amp;SOURCE=

    inc_userdetail has three parts, a listform and 2 dataviews.  On top of the second dataview I have a interactive button that will link to NewForm_Custom1.aspx but it must pass the UID value that was sent from inc_UserDetail.aspx

    right now the textbox on NewForm_Custom1.asp shows up with a text value of {@Title}

    Matt Pinkston

    Tuesday, March 19, 2013 4:49 PM
  • Hi,

    Can  you check the  NewForm.aspx form to see whether the UID query string have been passed to the new form successfully? On button click, how do  you get the UID from the URL? I think you need to use javascript behind the button to open the NewForm.aspx page with the correct UID. You can try the script below:

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

    <script type="text/javascript">

    function getUrlVars()

    {

        var vars = [], hash;

        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

        for(var i = 0; i < hashes.length; i++)

        {

            hash = hashes[i].split('=');

            vars.push(hash[0]);

            vars[hash[0]] = hash[1];

        }

        return vars;

    }

    function buttonclick ()

    {

    var string= getUrlVars()["UID"];

    alert(string);

    var string2= "URL to the new form NewForm_Custom1.aspx?UID="+string;

    window.open(string2);

    };

    </script>

    <button text="open new form" onclick="javascript:buttonclick()"></button>

    In this way, on button click on inc_userdetail.aspx, the NewForm_Custom1.aspx will be opened with UID as query string. In this way, the form field can get the correct query string.

    Thanks,

    Entan Ming

    Entan Ming
    TechNet Community Support

    Monday, March 25, 2013 10:27 AM
    Moderator