Solved

How do I hide formfields for some users in wss

Posted on 2008-10-06
1
1,356 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
[X]
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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Suggested Courses

632 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