Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to edit Master Page

How to edit Master Page

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shalini_U
    wrote on last edited by
    #1

    HiEveryone!!! I'm using Master page in my website.... When the user logged in, the asp menu button of the master page should be enabled or disabled according to the user permission.... How to do this? Plz Reply!!!!!!!! I Cannot able to access the controls of Master Page in Code Behind.. How to access those controls and edit the properties of those controls???

    C S 2 Replies Last reply
    0
    • S Shalini_U

      HiEveryone!!! I'm using Master page in my website.... When the user logged in, the asp menu button of the master page should be enabled or disabled according to the user permission.... How to do this? Plz Reply!!!!!!!! I Cannot able to access the controls of Master Page in Code Behind.. How to access those controls and edit the properties of those controls???

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Shalini_U wrote:

      How to do this? Plz Reply!!!!!!!!

      With code.

      Shalini_U wrote:

      I Cannot able to access the controls of Master Page in Code Behind..

      Yes you can. THe Master property, returns a MasterPage. What you need, is to upcast that to an instance of your master page class. Although, I think you should be able to handle all this permissions stuff inside the master page class itself, what I do if I ever use master page, is create a new base class for all my pages, which has a strongly typed MasterPage property that returns the upcast Master page. Then I can access the methods however I want. Of course, not being a hack programmer, I never make the controls on the master page public, I use methods and properties to allow only the required access.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      S 1 Reply Last reply
      0
      • C Christian Graus

        Shalini_U wrote:

        How to do this? Plz Reply!!!!!!!!

        With code.

        Shalini_U wrote:

        I Cannot able to access the controls of Master Page in Code Behind..

        Yes you can. THe Master property, returns a MasterPage. What you need, is to upcast that to an instance of your master page class. Although, I think you should be able to handle all this permissions stuff inside the master page class itself, what I do if I ever use master page, is create a new base class for all my pages, which has a strongly typed MasterPage property that returns the upcast Master page. Then I can access the methods however I want. Of course, not being a hack programmer, I never make the controls on the master page public, I use methods and properties to allow only the required access.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        S Offline
        S Offline
        Shalini_U
        wrote on last edited by
        #3

        Permission Means, just to check whether the user is enabled for a particular feature... So that the particular button is enabled for him... for this, I'll get the information abt the user whether the user is enabled or not from the database table. Then , I hav to set that particular button to enabled or disable. When I'm tried to get the control of Master Page, I can't do this in code behind... Is any other way to achiive this??

        C S N 3 Replies Last reply
        0
        • S Shalini_U

          Permission Means, just to check whether the user is enabled for a particular feature... So that the particular button is enabled for him... for this, I'll get the information abt the user whether the user is enabled or not from the database table. Then , I hav to set that particular button to enabled or disable. When I'm tried to get the control of Master Page, I can't do this in code behind... Is any other way to achiive this??

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Shalini_U wrote:

          When I'm tried to get the control of Master Page, I can't do this in code behind... Is any other way to achiive this??

          I guess you need to read my answer again, I explained exactly how to do it. And, as I said, the session should store details of who is logged in, so why can't your master page check for itself what it should show as a result ?

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          S 1 Reply Last reply
          0
          • S Shalini_U

            Permission Means, just to check whether the user is enabled for a particular feature... So that the particular button is enabled for him... for this, I'll get the information abt the user whether the user is enabled or not from the database table. Then , I hav to set that particular button to enabled or disable. When I'm tried to get the control of Master Page, I can't do this in code behind... Is any other way to achiive this??

            S Offline
            S Offline
            sashidhar
            wrote on last edited by
            #5

            if You are Using forms authentication

            //I did it for Image Button replace it for required menuitem
            if (Page.User.Identity.IsAuthenticated)
            {
            //logout
            ((Image)Master.FindControl("ImageButtonLogin")).Visible = false;//login ImageButton
            ((Image)Master.FindControl("ImageButtonLogout")).Visible = true;//logout ImageButton

                }  
            

            If this is not you are looking for sorry..!

            MyFirstArticlePublished: MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

            C 1 Reply Last reply
            0
            • S sashidhar

              if You are Using forms authentication

              //I did it for Image Button replace it for required menuitem
              if (Page.User.Identity.IsAuthenticated)
              {
              //logout
              ((Image)Master.FindControl("ImageButtonLogin")).Visible = false;//login ImageButton
              ((Image)Master.FindControl("ImageButtonLogout")).Visible = true;//logout ImageButton

                  }  
              

              If this is not you are looking for sorry..!

              MyFirstArticlePublished: MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Yes, this sort of thing will work, but it's ugly. Creating a strongly typed property is a far nicer solution IMO.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              1 Reply Last reply
              0
              • S Shalini_U

                Permission Means, just to check whether the user is enabled for a particular feature... So that the particular button is enabled for him... for this, I'll get the information abt the user whether the user is enabled or not from the database table. Then , I hav to set that particular button to enabled or disable. When I'm tried to get the control of Master Page, I can't do this in code behind... Is any other way to achiive this??

                N Offline
                N Offline
                nagendrathecoder
                wrote on last edited by
                #7

                Shalini_U wrote:

                I can't do this in code behind... Is any other way to achiive this??

                Ofcourse you can. I think you didn't understand what CG told you to do. Thats the best option, but if still you need code then try this:

                HtmlForm frm = (HtmlForm)Page.Master.FindControl("form_id");
                Menu mnu = (Menu)frm.FindControl("menu_id");
                mnu.Enabled = false;

                S 1 Reply Last reply
                0
                • C Christian Graus

                  Shalini_U wrote:

                  When I'm tried to get the control of Master Page, I can't do this in code behind... Is any other way to achiive this??

                  I guess you need to read my answer again, I explained exactly how to do it. And, as I said, the session should store details of who is logged in, so why can't your master page check for itself what it should show as a result ?

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  S Offline
                  S Offline
                  Shalini_U
                  wrote on last edited by
                  #8

                  I can't Get u... I stored the user details in session.. I can'access the controls and properties of the master page in it's cs file...

                  1 Reply Last reply
                  0
                  • N nagendrathecoder

                    Shalini_U wrote:

                    I can't do this in code behind... Is any other way to achiive this??

                    Ofcourse you can. I think you didn't understand what CG told you to do. Thats the best option, but if still you need code then try this:

                    HtmlForm frm = (HtmlForm)Page.Master.FindControl("form_id");
                    Menu mnu = (Menu)frm.FindControl("menu_id");
                    mnu.Enabled = false;

                    S Offline
                    S Offline
                    Shalini_U
                    wrote on last edited by
                    #9

                    Hi! Thank U..... I used that Code... But, error occurs that "Object Reference Not set to an instance of Object"

                    N 1 Reply Last reply
                    0
                    • S Shalini_U

                      HiEveryone!!! I'm using Master page in my website.... When the user logged in, the asp menu button of the master page should be enabled or disabled according to the user permission.... How to do this? Plz Reply!!!!!!!! I Cannot able to access the controls of Master Page in Code Behind.. How to access those controls and edit the properties of those controls???

                      S Offline
                      S Offline
                      Sachin Dubey
                      wrote on last edited by
                      #10

                      you can use like this... if(UserHasPermission) { Control ctr=this.Master.Findcontrol("ControlID") as Control; ctr.Enabeled=True; }

                      1 Reply Last reply
                      0
                      • S Shalini_U

                        Hi! Thank U..... I used that Code... But, error occurs that "Object Reference Not set to an instance of Object"

                        N Offline
                        N Offline
                        nagendrathecoder
                        wrote on last edited by
                        #11

                        where did error occurred? Can you show me your code?

                        S 1 Reply Last reply
                        0
                        • N nagendrathecoder

                          where did error occurred? Can you show me your code?

                          S Offline
                          S Offline
                          Shalini_U
                          wrote on last edited by
                          #12

                          MenuItem mnu = (MenuItem)frm.FindControl("menuitem1"); This shows error..... I used this code now.. Menu1.Items[3].Enabled = true; It's working for me......... Thank you for ur idea...

                          N 1 Reply Last reply
                          0
                          • S Shalini_U

                            MenuItem mnu = (MenuItem)frm.FindControl("menuitem1"); This shows error..... I used this code now.. Menu1.Items[3].Enabled = true; It's working for me......... Thank you for ur idea...

                            N Offline
                            N Offline
                            nagendrathecoder
                            wrote on last edited by
                            #13

                            Its good that you worked it out but this is not a good way to achieve it. It you can, try to implement the way told above. :)

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups