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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Handle master page button(s) click events on content page

Handle master page button(s) click events on content page

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netdesignsales
2 Posts 1 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.
  • D Offline
    D Offline
    De_Novice
    wrote on last edited by
    #1

    I have a master page ( masterpage.master) that has 2 link buttons lnkbtn_save and lnkbtn_edit. I have 2 content pages ( product and customer). When the user is on customer.aspx and clicks the lnkbtn_edit I want the controls on the customer page to be enabled and when the user clicks lnkbtn_save, I want the customer data to be saved. Basically the linkbuttons click event needs to be handles in the content page. learning for the fist process in this video ()[^] I could create a click event for one link button. How would I do this for two buttons. Here is my code:-- masterpage.aspx.vb

    Partial Class MasterPage
    Inherits System.Web.UI.MasterPage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    
    Protected Sub lnkbtn\_save\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    
    End Sub
    
    Public ReadOnly Property Masterbtnsave() As LinkButton
        Get
            Return lnkbtn\_Save
        End Get
    
    End Property
    

    End Class

    customer.aspx.vb

    Partial Class customer
    Inherits System.Web.UI.Page

    Protected Sub Masterbtnsave\_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("from customer page")
    End Sub
    Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        AddHandler Me.Master.Masterbtnsave.click, AddressOf Masterbtnsave\_Click
    
    End Sub
    

    End Class

    My question is: in the masterpage code behind I am returning the actual name of the lnkbutton in the property, how can I make this such that it returns the name of the button that was clicked. And then in the content page based on the button that was clicked some code is executed. Any help will be appreciated

    D 1 Reply Last reply
    0
    • D De_Novice

      I have a master page ( masterpage.master) that has 2 link buttons lnkbtn_save and lnkbtn_edit. I have 2 content pages ( product and customer). When the user is on customer.aspx and clicks the lnkbtn_edit I want the controls on the customer page to be enabled and when the user clicks lnkbtn_save, I want the customer data to be saved. Basically the linkbuttons click event needs to be handles in the content page. learning for the fist process in this video ()[^] I could create a click event for one link button. How would I do this for two buttons. Here is my code:-- masterpage.aspx.vb

      Partial Class MasterPage
      Inherits System.Web.UI.MasterPage
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

      End Sub
      
      Protected Sub lnkbtn\_save\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
      
      End Sub
      
      Public ReadOnly Property Masterbtnsave() As LinkButton
          Get
              Return lnkbtn\_Save
          End Get
      
      End Property
      

      End Class

      customer.aspx.vb

      Partial Class customer
      Inherits System.Web.UI.Page

      Protected Sub Masterbtnsave\_Click(ByVal sender As Object, ByVal e As System.EventArgs)
          MsgBox("from customer page")
      End Sub
      Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
          AddHandler Me.Master.Masterbtnsave.click, AddressOf Masterbtnsave\_Click
      
      End Sub
      

      End Class

      My question is: in the masterpage code behind I am returning the actual name of the lnkbutton in the property, how can I make this such that it returns the name of the button that was clicked. And then in the content page based on the button that was clicked some code is executed. Any help will be appreciated

      D Offline
      D Offline
      De_Novice
      wrote on last edited by
      #2

      There is also an abstract approach. I am new to classes and delegate events, kindlt explain in detail to a beginner.

      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