Solved

How do I hide formfields for some users in wss

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now