Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I hide formfields for some users in wss

Posted on 2008-10-06
1
Medium Priority
?
1,362 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

972 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