How can I write a code that triggers when clicking on Save button

I want to hide certain fields inside my tracking list, if the login user is not part of the “Managers” group.
To do so I want to add the following Page-load code inside a web part :-
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb())
{SPGroup group = site.Groups["Managers"];
bool isUser = site.IsCurrentUserMemberOfGroup(group.ID);
if (isUser)
{textbox.Visible=false;}}
And the following custom code that triggers when saving the form :-
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists["ListName"];web.AllowUnsafeUpdates = true;
SPListItem item = list.Items[SPContext.Current.ListItem.UniqueId];
txtTitle.Text = item["Title"] as string;item.Update();web.AllowUnsafeUpdates = false;
But I am not sure where exactly I should add the custom code for the save button ? I tried writing it inside the Oninit method , but I got many errors as shown below:-
So can anyone advice how i should write the web part to include the Page load & the custom save button code?
second question in general is my above approach considered valid , i mean to hide/show list columns using web parts ?

Hi,
According to your post, my understanding is that you want to hide/show list columns based on specify the permission for Users, SharePoint Groups or Active Directory Groups.
Here is a solution from CodePlex for your reference:
SharePoint 2013 Column & View Permission
https://sp2013columnpermission.codeplex.com/
Best Regards
Dennis Guo
TechNet Community Support

Similar Messages

  • How can I stop a JFrame from closing when clicking the close button.

    I need to display a dialog when a user attempts to close my app, giving them the option to close, minimize or cancel. How can I stop the form from closing after the user makes his selection? I have the folllowing code, but my form still closes after selecting an option:
    private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
            //An array of Strings to be used a buttons in a JOptionDialog
            String[] options = {"Close", "Minimize", "Cancel"};
            //Determines what the user wants to do
            int result = JOptionPane.showOptionDialog(null, "What to you want to do?  Close the application, minimize or cancel?", "Please select an option...", 0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
           //Determines what to do, depending on the user's choice
            if (result == 0) {
                //Close the application
                System.exit(0);
            } else if (result == 1) {
                //Minimize the application
                this.setState(Frame.ICONIFIED);
        }Any help would be much appreciated!

    import java.awt.event.*;
    import javax.swing.*;
    public class test extends JFrame {
         public static void main( String[] args ) {
              new test();
         public test() {
              setSize( 200, 200 );
              //the next line makes the JFrame not close
              setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
              //now add a listener that does the trick
              addWindowListener( new WindowAdapter() {
                        public void windowClosing( WindowEvent e ) {
                             //ask the user and do whatever you wish
              setVisible( true );
    }

  • How can i enable the html:text box when clicking the html:button

    Hi,
    i have a text box which is disabled defaultly and i want to enable it when i click on submit button.
    <html:button property="new" value="new">
    <html:text property="name" disabled="true"/>
    how i will enable that text filed? please tell me?
    Thanks,
    swarupa

    try using javascript onclick attribute:
    onclick="document.form.name.disabled=false"
    m

  • How can i write a code to get sume of value from days.

    Hi,
    how can i write a code to get the sum of value of days(example 1 to 30).
    This is in BPS ...
    i created multi planning area and creted planning function with {keyfigure name,planning area,days}.
    now i want to read all the actual values  from basic planing area(basic cube) and calculate the sum of the value.if you have idea can you share the code.
    ENTRIES = VARC ( 'zvardays' ).     ex(zvardays like 28 days or 29 days or 30 days or 31 days)
    COUNT = ENTRIES.
    *Get the all the days value from actual
    FOREACH PAREA = 'basic planning area'.
      COUNT = 1.
    DO
         SUM = SUM + {amount, count}      (amount is a keyfirgure value)
    ENDDO.
    COUNT = COUNT+1.
       SUMACT =  SUM.
    ENDFOR.
    can you correct the above code ....to read the values and sum of the those value.
    Thanks...

    Hi ..
    That is ok..
    Can you provide sample code for my requirement..
    and also how can i pass the error message (can you help me syntax )
    and if my acutal-total  is not equal to plan-total  then
    i have to pass the error message and then  i have to restrict save the data  how i can i restrict(user can not save the data until the values should be equal) .
    Can you help me it is very urgent..
    thanks.//
    Edited by: Eyda rose on Jun 4, 2008 9:29 PM

  • How can I write HTML code in this forums

    Sorry but I didn't know where to post this thread.....
    How can I write HTML code in this forums?

    Hello,
    Every piece of code in your post should be wrapped with the forum tags [ code] and [ /code], without the blanks.
    In case of the &lt;a> tag, that is not enough. In this case, you have several options. The most elegant one is to use the entity name for the less-then sign - & lt; - without any spaces. Other options is to add a space between the less-then and the ‘a’ character (and make a note of it) or change the less-then character with a left bracket one.
    When posting code, you should always use the forum preview option, just to make sure the forum software “understood” your code correctly.
    Hope this helps,
    Arie.

  • How can we write the code for opening the command prompt and closing the

    how can we write the code in java for opening the command prompt and closing the cmd prompt from eclipse (cmd prompt should close when click on the turminate button in eclipse)

    rakeshsikha wrote:
    how can we write the code for opening the command prompt and closing theBy typing in Eclipse (which you seemingly have)?

  • How can print a report from form 6i,  when I press a button?

    hi Friends,
    How can print a report from form 6i, when I press a button?
    When i press a button from Form 6i, the report should print through printer.
    I have done it by using report parameter DESTYPE Printer but problem is that when I press a button printer dialogue box appear and then I give command Print to printer, I don’t want to show Printer dialogue box.
    I want when I press a button form Forms 6i , printer will print my report directly.
    Please send me the solution of this problem.
    Best regards,
    Shahzad

    Hi
    If You are using Client server application then to passing to Add all Print Parameter in the Host Command.
    Means Print command in unix to Host(lp.............) and Other Parameter to file name of the report to print.
    If You not Use Client Server Application the Also Passing a Host Command in Button-Pressed Event and Run.

  • How can you soft reset an iphone 4s when power on/off button not working

    How can you soft reset an iphone 4s when your on/ off button is not working?
    My voicemail messages are unobtainable and i'm trying to work out how to fix this.

    Sorry you don't.

  • How can i write the code in xml publisher desktop

    hi all
    How and where can i write the code in xml publisher desktop ???
    shall i know how to write xml code or what ??
    in which part can i write the code if i have more than one query ?

    hi dear
    Thanks for ur replay...
    What i mean is : i used to work on reports builder,so :
    1- i used to create more than query in some reports.
    2- create formulas ,procedures....
    NOW i want to create the same reports by using xml publisher desktop, so how can i do that...
    when i use {color:#ff0000}report wizard{color}, i can not or i don`t know how to use more than one query, create formulas or procedures.
    Please help me.
    Thanks again.

  • How can I write a program that compiles without warnings?

    I tried the following with the 1.5 beta-compiler (build 28; I think):
    class Y {
         public static final class Pair<X,Y> {
           private X fst;
           private Y snd;
           public Pair(X fst, Y snd) {this.fst=fst; this.snd=snd;}
           public X getFirst() { return fst; }
           public Y getSecond() { return snd; }
           public String toString() { return "("+fst+","+snd+")"; }
      public static void main(String... args) {
         Pair[] pairArr = new Pair[10];              // supposed to be an array of Pair<Integer,Integer>
         for (int i=0; i<pairArr.length; i++)
             pairArr[i] = new Pair<Integer,Integer>(i,i);
         for (int i=0; i<pairArr.length; i++) {
             Pair<Integer,Integer> p = pairArr; // unchecked warning
         System.out.println(p);
         Integer first = p.getFirst();
         Integer second = p.getSecond();
    // ... more stuff ...
    It turns out that I get an unchecked warning when I extract an element from the array of pairs. Okay, that's fine. How can I avoid the warning? I had expected that an explicit cast would help.
      Pair<Integer,Integer> p = (Pair<Integer,Integer> )pairArr;
    With a cast I'm telling the compiler: "I _know_ what I'm doing; please trust me." But the compiler still issues a warning.
    How can I write a warning-free program in this case? The only thing I can think of, is not using the parameterized type Pair in its parameterized form. But it's not the idea of Java Generics that I refrain from using parameterized types. What am I missing?

    It turns out that I get an unchecked warning when I
    extract an element from the array of pairs. Okay,
    that's fine. How can I avoid the warning? I had
    expected that an explicit cast would help.
    Pair<Integer,Integer> p = (Pair<Integer,Integer>
    )pairArr;
    With a cast I'm telling the compiler: "I _know_ what
    I'm doing; please trust me."  But the compiler still
    issues a warning.  Yes, but at least you were able to change the warning from "unchecked assignment" to "unchecked cast" which is a little shorter ;-)
    Seriously , since arrays of generic types are disallowed, there is probably no way to get rid of these warnings - which makes a strong point for eliminating "unchecked" warnings altogether (see the other thread "selectively suppressing compiler warnings")
    Cheerio,
    Gernot

  • HT2589 how can i get the code that they were asking?i cant see the code for the gift certificate?

    they keep on asking for a gift certificate code..to complete using itunes store..but how can i redeem my code ?where can i get that?

    Click here and request assistance. Gift cards are usually if not always final sale because it would be easy enough for someone dishonest to abuse returns or replacements of them.
    (58640)

  • How can I customize the webpage that appears when I click add a new tab? I would like it to be google please.

    When I click the + tab option, the page goes to results by bing. I'm not a fan of this. Can you help me fix that?

    Type '''about:config''' in URL
    * filter - '''browser.newtab.url''' > Change the value to ''Google.com"

  • How can I rotate an image in iAd by clicking on a button?

    I wan't to create a iBooks Author Widget with an image (asset, protractor) that will rotate when I click a button (object).
    The rotation angle must be adjustable by a TextField.
    Please help me with this, my JavaScripts skills let me a bit down on this...
    With Regards, Tom
    So, the protractor (in dutch Geodriehoek) must rotate as I click on the button.

    Hey Tom,
    In addition to the spin action, you can use a bit of javascript to apply a transform to any object on a page to set an arbitrary angle and doing it within a transition, you can smoothly animate the rotation.
    Given a page with an object subclassed from view - like your ImageView - and a couple of buttons, you can trap the button taps and within the onViewActivate code look at the current transform (rotation) value of the object and increment it by plus or minus 1 to rotate in either direction.
    The increment button would have something like:
    this.onViewActivate = function (event) {
              // Code here for the "Activated" event.
         // myView is the outlet name of the object on the page I want to rotate
       var myView = this.viewController.outlets.view;
       var newValue = null;
         // see if the object has any transform (rotation) to begin with
        if (myView._transform == "none") {
            newValue = "rotateZ(0deg)";
        else {
              // parse the existing transform to get the current value
            var start = myView._transform.indexOf('(') + 1 ;
            var end = myView._transform.indexOf('deg)');
            var value = myView._transform.substring(start,end);
              // increment the value
            newValue =  "rotateZ(" + ++value + "deg)";
       var myAngleTransition = new iAd.Transition({
            target : myView,
            properties : ['transform'],
            from : [myView._transform],
            to : [newValue],
            duration : [1.5]
        myAngleTransition.start();
    and the decrement button would have the same code with "++value" changed to "--value".  This sample steps by 1 as well but you can add smaller values to value if you want finer control/
    There's probably many more elegant ways to do this but this works none the less.
    Cheers,
    -Mark

  • How can I call a custom javascript function when clicking on cfgrid cell.

    I would like to call a custom javascript function when
    clicking on a cell in an cfgrid (of html format). The closest thing
    I can find is to use the HREF="" attribute, but it doesn't seem to
    work with javascript inside it.
    Simple example:
    <cfgridcolumn name="Foo" header="Foo"
    href="javascript:customFunction(#ID#);">
    Do I need to tap into the underlying Ext JS funtionality? If
    so, where can I start?
    Thanks!

    Hi,
    According to your post, my understanding is that you want to hide/show list columns based on specify the permission for Users, SharePoint Groups or Active Directory Groups.
    Here is a solution from CodePlex for your reference:
    SharePoint 2013 Column & View Permission
    https://sp2013columnpermission.codeplex.com/
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How can I write java code in web dynpro to show KM content document?

    Dear all developer
    SDN developer who have any easy example java code for get and show KM content documents(documents/com.xx.km/.). We are develop this project by Netweaver Studio 7.0 and using WEB Dynpro application.
    Thank for all comment and advice.
    Jumnong Boonma

    Hi
    i dont have the exact code but yes..i can refer to the link for Web Dynpro applications for the Portal.
    [http://help.sap.com/erp2005_ehp_03/helpdata/EN/42/fa080514793ee6e10000000a1553f7/frameset.htm]
    Here look out for Absolute Navigation.
    Hope it helps...
    Thanks..

Maybe you are looking for