Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using VB.Net
I have a dropdown list on masterpage, I need to fire its selectedindexchange event in content pages as if its a control of content page. I want to pass this event to content page. Is it possible.
Thanks all
Posted
Updated 14-Nov-13 1:04am
v3
Comments
Er Daljeet Singh 14-Nov-13 5:41am    
yes it is possible with the help of Event and Delegates...

C#
protected void Page_Load(object sender, EventArgs e)
{

    DropDownList drp = (DropDownList)Page.Master.FindControl("drpDownlist");
    drp.SelectedIndexChanged+=new EventHandler(drp_SelectedIndexChanged);
}

    void drp_SelectedIndexChanged(object sender, EventArgs e)
    {
            
    }


just write this code in your content page and it is done.
 
Share this answer
 
Comments
[no name] 14-Nov-13 6:33am    
Thank you for your answer... but I am sorry I forgot to mention that my project is in VB.Net. Though I converted your code to VB.Net, its not firing selectedIndexChanged Event.. any soln??
Er Daljeet Singh 14-Nov-13 7:11am    
have you changed the name of dropdownlist in the code or not.
or try to do one thing run your code check the name of the dropdownlist in browser and copy that name into you code.Something if you place some control in master page and find that controls on content page then name of the control will be changed.

[no name] 14-Nov-13 7:30am    
I have changed name properly, I didn't raised event properly. Now when I raised event from MasterPage and handling the event in Pageload, its giving error... SelectedIndexChanged is an event and cannot be called directly, use raise event to raise it.
Er Daljeet Singh 15-Nov-13 7:08am    
let me clear one thing..
you are having a master page on which you have dropdownlist now you to fire the dropdownlist_SelectedIndexChanged from content page.
just do one thing.
dont fire any event of dropdown from master page and then write the code i posted in the content page.
In Master page

VB
Public Event SelectedIndexChange(ByVal sender As Object, ByVal e As System.EventArgs)
 
Protected Sub drpmember_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpmember.SelectedIndexChanged
 
        RaiseEvent SelectedIndexChange(Me, e)
End Sub


In PreInit event of content page

VB
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim drp As DropDownList = DirectCast(Page.Master.FindControl("drpmember"), DropDownList)
AddHandler Master.SelectedIndexChange, AddressOf DelegateName
End Sub



In Content page

VB
Protected Sub DelegateName(sender As Object, e As System.EventArgs)
''' Your Logic
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900