THE MICROSOFT MASTER PAGES FUDGE

G

Guest

keywords: asp.net master page rubbish

I have written a custom control. The control is a simple html Tab menu
control. The control inherits from DataBoundControl and implements
INamingContainer, IPostBackEventHanlder and IPostBackDataHandler. The control
is engineered to use a hidden client-side input textbox which stores a
selected index variable to enable the IPostBackDataHandler to determine a
change in tab and trigger a redraw of html. I am also controlling the
necessary viewstate to support the selected index and data set variables. My
control works fine and I am able to trap the server-side events for
OnTabClick and re-draw my control on DataChanged event. My problems arise
when my control is added to a Master page and in the event handler I redirect
to a Content page. Once I do this none of the control’s event seem to be
being fired, although the postback event handler must be being executed as
the content page is being merged!!! Crazy!!!. Neither the control’s
LoadPostBackData or RaisePostBackEvent methods are executing and I have tried
everything to figure out why this is the case and have now spent nearly two
weeks re-writing the custom control’s methods. Please, please, please,
Microsoft, help me figure this master page madness out as I am completely
stuck!!!
 
G

Guest

Mark said:
keywords: asp.net master page rubbish

I have written a custom control. The control is a simple html Tab menu
control. The control inherits from DataBoundControl and implements
INamingContainer, IPostBackEventHanlder and IPostBackDataHandler. The control
is engineered to use a hidden client-side input textbox which stores a
selected index variable to enable the IPostBackDataHandler to determine a
change in tab and trigger a redraw of html. I am also controlling the
necessary viewstate to support the selected index and data set variables. My
control works fine and I am able to trap the server-side events for
OnTabClick and re-draw my control on DataChanged event. My problems arise
when my control is added to a Master page and in the event handler I redirect
to a Content page. Once I do this none of the control’s event seem to be
being fired, although the postback event handler must be being executed as
the content page is being merged!!! Crazy!!!. Neither the control’s
LoadPostBackData or RaisePostBackEvent methods are executing and I have tried
everything to figure out why this is the case and have now spent nearly two
weeks re-writing the custom control’s methods. Please, please, please,
Microsoft, help me figure this master page madness out as I am completely
stuck!!!

Ouch. Please use line breaks to separate paragraphs.

One thing that changes when you put a control in a master page is the
names that is generated for the html elements. Do you hard code the
names of the elements in the client code?
 
G

Guest

Goran,

What paragraphs? ;-)

Client-side code is working fine, I have checked using view source.

I am using the ClientScriptManager method RegisterHiddenField(string
hiddenFieldName, string hiddenFieldInitialValue) to output my hidden textbox.

As I have stated the control is working fine when I comment out the redirect
to content page in server-side event handler.
 
G

Guest

ok, I think what's going on here is quite simply that the content page is
re-initializing the control.

I exposed the selected index as a property, referenced the control from the
content page and displayed the selected index, and hey-presto it was back to
-1!

Naturally the next question is, is there anyway stopping the
re-initialization of controls on the master page when redirecting to a
content page?

Where are all the mvps when you need them? Have they deserted the newsgroups?
 
M

Mark Rae

Naturally the next question is, is there anyway stopping the
re-initialization of controls on the master page when redirecting to a
content page?

A step back here...

This is a common misconception with MasterPages / content pages - they are
not the same as framesets... In fact, a MasterPage isn't actually a 'page'
at all - it's a UserControl...

When you redirect to a content page, the entire page is rebuilt from the
bottom up, and that includes opening the MasterPage and merging its contents
with the content page to form a single HTML stream to be sent down to the
browser...
Where are all the mvps when you need them? Have they deserted the
newsgroups?

Most probably they are all earning their own living... :)
 
G

Guest

- Mark

The only misconception I think I have made with master pages is that I
thought they were designed to enable a clear page\content layout and
separation for web-sites. This is the only likening I had of master pages
with framesets. Which is obviously what they do ..... as long as the content
of the master page is STATIC!!

Perhaps my menu control should reside in another content page? How are
people providing menu driven web-sites with page\content separation?
 
M

Mark Rae

Perhaps my menu control should reside in another content page?

I'd suggest that your menu control should reside in your MasterPage - that's
certainly the way I do it...
How are people providing menu driven web-sites with page\content
separation?

If the menu needs to change according to the content page, it's a simple
enough thing to modify it in the content page's Page_Load event...

Menu mnuMaster = (Menu)Master.FindControl("MyMenu");
mnuMaster.Items.Add(.......................);

etc
 
G

Guest

There is no re-initialising going on, just initialising. When you do a
redirect you load a new page. There is no ViewState left from the
previous page as this is a completely new page.

If you want to persist any values, you have to either keep it on the
server, or send it along in the redirect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top