Linkbutton in Master page is not being fired when clicked the first time - Confused...

Last post 12-26-2006 12:20 PM by Gloriayen. 4 replies.

Sort Posts:

  • Linkbutton in Master page is not being fired when clicked the first time - Confused...

    12-21-2006, 9:14 PM
    • Loading...
    • Gloriayen
    • Joined on 03-30-2006, 12:36 PM
    • Posts 17

    I have a linkbutton placed in the master page. What I want to achieve is, when clicked, the content page will be directed to another page, and the appearance of the the linkbutton will be changed.  The link button is defined as below:

        <asp:LinkButton ID="LinkButton1" runat="server"  PostBackUrl="xxx.aspx" CssClass="menuNormal" >XXX</asp:LinkButton>

    I also have the button click event defined as below:

        Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
                    LinkButton1.CssClass = "menuSelected"
        End Sub

    What happens is:

    When the link button is clicked the first time, the master page is initiated, the content page is initiated, and then the master page is loaded. But the button_click event never fires. Therefore, the content page is changed to a different one but the appearance of the button remains the same.

    When the link button is clicked a second time,  the master page is initiated, the content page is initiated, the master page is loaded, AND then the button_click event is fired. Therefore, this time, the appearance of the button is changed.

    Why? And what do I need to do so "both" the appearance of the button will change, and the content page shows a new page, when the button is clicked the first time?

    I have tried to put the postbackurl into the LinkButton1_Click event but this time, the appearance of the button is changed BUT the content page does not get directed to a new page...

     HELP!!!

     

     

     

     

     

  • Re: Linkbutton in Master page is not being fired when clicked the first time - Confused...

    12-21-2006, 10:30 PM

    Sound like a life cycle issue, this should help

    http://www.tgreer.com/aspnet_html_04.html

    Happy programming 

    Don't forget to "Mark as Answer" if this post answered your question
    Life's good
    My Site
  • Re: Linkbutton in Master page is not being fired when clicked the first time - Confused...

    12-22-2006, 1:06 AM
    • Loading...
    • pushp_aspnet
    • Joined on 10-19-2006, 1:27 PM
    • Hyderabad,India
    • Posts 447

    Hi gloriayen,

    Add the below code in the page_load of your target page( xxx.aspx):

    --------------------------------------

    If (Not (Page.PreviousPage) Is Nothing) Then
        Dim 
    lb As LinkButton = CType(Me.Master.FindControl("LinkButton1"),LinkButton)
        lb.CssClass 
    "menuSelected"
    End If

    ------------------------------------------------------------------- 

    Hope this helps. 

     

    Home Is Where the Wind Blows
    http://pushpontech.blogspot.com
  • Re: Linkbutton in Master page is not being fired when clicked the first time - Confused...

    12-22-2006, 1:48 AM
    Answer
    • Loading...
    • vbuser2004
    • Joined on 11-20-2004, 8:46 PM
    • Posts 43
    Here is a slight wrinkle to pushp_aspnet's solution...remove the If..then statement and put only this in the page load of xxx.aspx:
    Dim lb As LinkButton = CType(Me.Master.FindControl("LinkButton1"), LinkButton)
    lb.CssClass = "menuSelected"
    This will ensure that the link button always displays as selected when you are on that page, regardless of how the user got there.
    Good question!
    Good luck!
     
  • Re: Linkbutton in Master page is not being fired when clicked the first time - Confused...

    12-26-2006, 12:20 PM
    • Loading...
    • Gloriayen
    • Joined on 03-30-2006, 12:36 PM
    • Posts 17
    It works!! Yeah!! Thank you guys.Smile
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter