Solved

How do I hide formfields for some users in wss

Posted on 2008-10-06
1
1,351 Views
Last Modified: 2012-06-22
Hi,

I want to hide some controls for some users.
My form ( created by Sharepoint designer, (insert - sharepoint controls - custom list form.) has  3 inputs: Title, colA and colB

In my header I have some code to validate users, tits checkin if they are members of certain groups.

Sample:
<script  type="text/c#" runat="server">
    protected override void OnLoad(EventArgs e)
   {
        // avoid processing if not in display mode
        if (isMember("admins") > 2)
        {
admin = 1;
// show colA
        }
 }
</script>



To hide (or at least try to) I use the <% %> tags

      <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="New" FieldName="Title" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}"/>
                                          <SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="Title" ControlMode="New"/>
                                    </td>
                              </tr>
                              
                              
<% if(admin==1){
%>                        
                              <tr>
                                    <td width="190px" valign="top" class="ms-formlabel">
                                          <H3 class="ms-standardheader">
                                                <nobr>colA</nobr>
                                          </H3>
                                    </td>
                                    <td width="400px" valign="top" class="ms-formbody">
                                          <SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="colA" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@colA')}"/>
                                          <SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="colA" ControlMode="New"/>
                                    </td>
                              </tr>
<%
}
%>

                              <tr>
                                    <td width="190px" valign="top" class="ms-formlabel">
                                          <H3 class="ms-standardheader">
                                                <nobr>colB</nobr>
                                          </H3>
                                    </td>
                                    <td width="400px" valign="top" class="ms-formbody">
                                          <SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="New" FieldName="colB" __designer:bind="{ddwrt:DataBind('i',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@colB')}"/>
                                          <SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="colB" ControlMode="New"/>
                                    </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>
                        </table>
                  </td>
            </tr>
            
      </xsl:template>


 unfortunately I getthis error:

Parser Error Message: The 'XSL' property of 'WebPartPages:DataFormWebPart' does not allow child objects.

Source Error:

Parser Error Message: The 'XSL' property of 'WebPartPages:DataFormWebPart' does not allow child objects.

Source Error:


Line 128:                              </tr>
Line 129:                              
Line 130:                              <%
Line 131:                              if(admin==1){
Line 132:                              %><tr>
 
Source File: /Test/Lists/akjtest3/NewForm.aspx    Line: 130

Am I barking up the wrong tree ??
How should this be done ?

Best regards
Anders
0
Comment
Question by:dk_akj
1 Comment
 

Accepted Solution

by:
dk_akj earned 0 total points
ID: 22649633
If I put this:
<xsl:variable name="bVisible">false</xsl:variable>      

In the xsl:stylesheet I can control visiblity:
<xsl:if test="$bVisible='true'">
  <tr>
  <td width="190px" valign="top" class="ms-formlabel">
  <H3 class="ms-standardheader">
  <nobr>colA</nobr>
  </H3>
  </td>
  <td width="400px" valign="top" class="ms-formbody">
  <SharePoint:FormField  runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="colA"   __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims  (string(@ID)),'@colA')}"/>
  <SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="colA"   ControlMode="New"/></td>
  </tr>
</xsl:if>

It's not dynamic (yet), but is it a better way to go ??

Anders
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question