Event rasing through Service ([ServiceDependency])

Topics: Web Client Software Factory
May 19, 2008 at 7:14 AM
I have a MasterPage for my website. There are many UserControls which load or unloads depending upon the button(menu) clicked on the MasterPage. So I have a case in which I have to raise an event on the MasterPage from the UserControl. So I made a service to do this. I raise a event of the service on the click of a Button, which is present in the UserControl, then the service raises an event which is being listened on the MasterPage. It raises the event perfectly on the MasterPage. But the problem is this, that it happens after the PreRender event. So I am not able to load other usercontrol because of this. I get this error:

The RegisterRequiresViewStateEncryption() method needs to be called before or during Page_PreRender.


I can solve this by setting some session on the click and then Redirecting to the Default page, which has the same MastePage, and then check the for that session on the page load of the MasterPage and do whatever I want. But I want to avoid this.

Any suggestions?

Regards,
Charuk.
May 28, 2008 at 5:11 PM
Edited May 28, 2008 at 5:18 PM


charuk wrote:
I have a MasterPage for my website. There are many UserControls which load or unloads depending upon the button(menu) clicked on the MasterPage. Any suggestions?

Regards,
Charuk.

For the following I have a button on my Master Page called "MyButton1".   If I place the following code snippet in the Page_Load() of a page that utilizes the masterpage it will only write "Hello World" when the button is clicked.   Perhaps this may offer you another avenue to use..



if
(!string.IsNullOrEmpty(Request.Form.Get("ctl00$MyButton1")))
{
      Trace.Write(
"Hello world");

      // Change  master page button text
      Button myButton = (Button)Page.Master.FindControl("ctl00$MyButton1");
      myButton.Text =
"Clicked!";

 

}