Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I hide formfields for some users in wss

Posted on 2008-10-06
1
1,353 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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