Hide Any Control On A Web Enabled Form ~ an Easy Alternative Way - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Hide Any Control On A Web Enabled Form ~ an Easy Alternative Way

Last post 01-08-2010 12:35 PM by turfnsurf4me. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 01-08-2010 12:35 PM

    Hide Any Control On A Web Enabled Form ~ an Easy Alternative Way

    The following is predicated on having a web enabled form with code behind ( c# )



    Had the need to hide a button control on my web enabled form. I reviewed various articles and posts from the internet and frankly found them (although useful in their own right and I respect the people that volunteered the information)  way too much trouble for my tastes. I figured there just had to be a simpler way to do this,  well for me at any rate. And to my delight I did find a way, only 8 lines of code!...woohoo!

     Brief summary of what's needed.... 
    • 1 Textbox
    • Some conditional formatting on the button
    • 8 lines of code
    • 5 minutes of my time without having to mess with Form Data Connections and or other web services etc.



     The Details 

    1)  Placed a textbox on my form. Set the conditional formatting to hide the textbox. Named the textbox   txtHideFlag


    (optional )

    In the web.config file of the Sharepoint site of where my form resides, I added a Key Value pair variable that would contain the domain user names for people I only wanted to see the button on the form. I did this so I could easily change the names of peoples who were only required to see the button. Rather than hardcoding usernames in the code base, and then having to recompile, re-publish / deploy and so forth.


           Under <appSettings> in the web.config I added….  <add key="SecurityManagers" value="danb;stevek" /> 

      Obviously you're going to add the domain users of your domain.



    2)  Include System.Configuration to your code base


    Using System.Configuration;


    Then in my forms FormEvents_Loading() function I added the following code....


          XPathNavigator root = MainDataSource.CreateNavigator();

    string  _securityManagers = "";


    if (  ConfigurationManager.AppSettings["SecurityManagers"'] != null )


           _securityManagers  =  ConfigurationManager.AppSettings["SecurityManagers"']


    if(  ! _securityManagers.Contains( this.Application.User.UserName ) )

          root.SelectSingleNode("//mytxtHideFlag", NameSpaceManager).SetValue("HIDE");


          root.SelectSingleNode("//mytxtHideFlag", NameSpaceManager).SetValue("");


    I then configured the button's conditional formatting to hide itself if the mytxtHideFlag textbox = "HIDE".  So the logic / functionality is, if the domain user who is viewing the form in the web browswer, is contained in that list of usernames contained in the Key/Value variable ~( in the web.config) ~, the button will be visible. Otherwise, the button is hidden.



Page 1 of 1 (1 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.