Events with Master Pages
-
Hey all, I'm trying to get an application up and running using Master Pages and their content pages using events to check user input. The problem that I'm encountering is how and where to declare the events so they fire just within the page that is accessed and its master page. I've used events before but not with master pages, ie: all content pages are aspx pages. Is it necessary to create seperate classes to handle the interactivity with the events, and if so how do I interconnect them with the content pages? The data I've come across on Google is very generic so far and handles only one master page with one content page. I only have two master pages, but it is running me through the ringer trying to figure this out. I know that this jumbled question probably sounds like the ravings of a simpleton, but if y'all could give me a push in the right direction I would really appreciate it. Thanks in advance.:)
An American football fan - Go Seahawks!
I can't believe that the 49ers beat the Hawks twice :( Lil Turtle -
Hey all, I'm trying to get an application up and running using Master Pages and their content pages using events to check user input. The problem that I'm encountering is how and where to declare the events so they fire just within the page that is accessed and its master page. I've used events before but not with master pages, ie: all content pages are aspx pages. Is it necessary to create seperate classes to handle the interactivity with the events, and if so how do I interconnect them with the content pages? The data I've come across on Google is very generic so far and handles only one master page with one content page. I only have two master pages, but it is running me through the ringer trying to figure this out. I know that this jumbled question probably sounds like the ravings of a simpleton, but if y'all could give me a push in the right direction I would really appreciate it. Thanks in advance.:)
An American football fan - Go Seahawks!
I can't believe that the 49ers beat the Hawks twice :( Lil TurtleTo access master page controls from the content page do something like this.
protected void Page_Load(object sender, EventArgs e) { this.Init += new EventHandler(Page_Init); } protected void Page_Init(object sender, EventArgs e) { DropDownList ddl = (DropDownList)this.Master.FindControl("ddl"); ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged); } protected void ddl_SelectedIndexChanged(object sender, EventArgs e) { //put code here }
-
To access master page controls from the content page do something like this.
protected void Page_Load(object sender, EventArgs e) { this.Init += new EventHandler(Page_Init); } protected void Page_Init(object sender, EventArgs e) { DropDownList ddl = (DropDownList)this.Master.FindControl("ddl"); ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged); } protected void ddl_SelectedIndexChanged(object sender, EventArgs e) { //put code here }
Does this mean that I declare the event delegate on the master page?
An American football fan - Go Seahawks! Lil Turtle
-
Does this mean that I declare the event delegate on the master page?
An American football fan - Go Seahawks! Lil Turtle
No, thats not necessary. You just add the event in the content page.
-
No, thats not necessary. You just add the event in the content page.
Before my next question let me first thank you for all the help you've given me thus far, I do appreciate it. When I've used events before I had to add classes that handled the event information ie: Custom data Classes, EventArgs, and Custom Handlers. Is this still necessary with the above declaration? I can provide code samples if it'd help.
An American football fan - Go Seahawks! Lil Turtle
-
Before my next question let me first thank you for all the help you've given me thus far, I do appreciate it. When I've used events before I had to add classes that handled the event information ie: Custom data Classes, EventArgs, and Custom Handlers. Is this still necessary with the above declaration? I can provide code samples if it'd help.
An American football fan - Go Seahawks! Lil Turtle
You are attaching the delegate to the event with the += operator. Does that answer your question?
-
You are attaching the delegate to the event with the += operator. Does that answer your question?
Yes it does thank you.
An American football fan - Go Seahawks! Lil Turtle
-
Yes it does thank you.
An American football fan - Go Seahawks! Lil Turtle
no problem.