Events refuse to fire when using master pages

S

saturday

I've tried figuring this out as best I could, but I've already spent a
day trying to get this to work, and it's blocking further dev.

I have a page that is using master pages. I have a button in the
content page, but it refuses to execute its OnClick code.

I'll paste in the relevant code in question below. I suspect it has
something to do with master pages, but I'm not sure. I've created test
pages using sample code from MSDN that does not use master pages, and
the events work flawlessly. Oh yeah, and any "EnableViewState"
commands you see were added in by me. I got desperate and started
throwing them in several places, but they had no effect. For the
page_load, I've had it check for postbacks (when I still had my
repeater), but that had no effect either.

The aspx page:

<%@ Page Language="C#" MasterPageFile="~/Master.master"
AutoEventWireup="true" CodeFile="Page.aspx.cs" Inherits="Page"
Title="Untitled Page"%>

<asp:Content ID="Content1" ContentPlaceHolderID="Header"
Runat="Server">
&nbsp;
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" Runat="Server"
EnableViewState="true">
<asp:MultiView ID="MultiView" runat="server" EnableViewState="true">
<asp:View ID="View1" runat="server">
<asp:ImageButton ID="ImageButtonContinue" runat="server"
AlternateText="Continue" OnClick="ImageButtonContinue_Click"/>
<asp:LinkButton ID="LinkButton1" runat="server"
PostBackUrl="Default.aspx">LinkButton</asp:LinkButton></asp:View>
<asp:View ID="Login" runat="server">
</asp:View>
</asp:MultiView>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Footer"
Runat="Server">
</asp:Content>

The CS code behind:

protected void Page_Load(object sender, EventArgs e)
{
this.MultiView.SetActiveView(this.View1);
}

protected void ImageButtonContinue_Click1(object sender,
ImageClickEventArgs e)
{
Response.Redirect("Default.aspx"); //Break point is here, but
it's not happening.
//And yes, it breaks fine elsewhere.
}

Any help would be appreciated.
 
T

Tom John

Hi

Firstly your ImageButton is OnClick is pointing at
ImageButtonContinue_Click, whereas the codebehind method is called
ImageButtonContinue_Click1. But this would cause a compilation error,
so i'm guessing this is just a typo in what you posted.

Whith that fixed, which button are you finding is not posting back?
The ImageButton (ImageButtonContinue) is posting back fine. If it's
the LinkButton1 that's not wired up to the event handler.

Hope this helps

Tom
 
S

saturday

Hi Tom,

Sorry yes, that was a typo.

ImageButtonContinue is definitely not executing
ImageButtonContinue_Click1 for me. It's working for you? Something is
responding, Page_load is called again when I click the button, and the
breakpoint I set in there does fire, but the breakpoint in
ImageButtonContinue_Click1, which is on the Response.Redirect, does
not fire.

I did some further testing, and I don't think it has anything to do
with master pages anymore. I made another test page similar to the
original, but without master pages, and it, too, would not fire
events. I'm starting to think it has something to do with using code
behind? that's the only difference I can see between the MSDN sample
code I tried, which works fine in the same project, using inline C#
code (<script runat="server">C# code etc</script>), and my code.

Any ideas?
 
T

Tom John

The imagebutton event is firing fine form me, here's my complete code:

MasterPage:

<%@ Page Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication3.WebForm1" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
runat="server">
<asp:MultiView ID="MultiView" runat="server"
EnableViewState="true">
<asp:View ID="View1" runat="server">
<asp:ImageButton ID="ImageButtonContinue" runat="server"
AlternateText="Continue"
OnClick="ImageButtonContinue_Click" />
<asp:LinkButton ID="LinkButton1" runat="server"
LinkButton</asp:LinkButton></asp:View>
<asp:View ID="Login" runat="server">
</asp:View>
</asp:MultiView>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3"
runat="server">
</asp:Content>


WebForm:

<%@ Page Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication3.WebForm1" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
runat="server">
<asp:MultiView ID="MultiView" runat="server"
EnableViewState="true">
<asp:View ID="View1" runat="server">
<asp:ImageButton ID="ImageButtonContinue" runat="server"
AlternateText="Continue"
OnClick="ImageButtonContinue_Click" />
<asp:LinkButton ID="LinkButton1" runat="server"
LinkButton</asp:LinkButton></asp:View>
<asp:View ID="Login" runat="server">
</asp:View>
</asp:MultiView>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3"
runat="server">
</asp:Content>


WebForm Code Behind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebApplication3
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.MultiView.SetActiveView(this.View1);
}

protected void ImageButtonContinue_Click(object sender,
ImageClickEventArgs e)
{
// Stick a break point on the next line.
Response.Redirect("Default.aspx");
}

}
}


Maybe start with a new project to rule out any other problems.

Hope this helps,

Tom
 
S

saturday

Oooook. So I switched the browser to IE, and it worked fine ( I was
using FF before, which worked fine when I was dev-ing on VS 2k3).
Thanks for all your help. Hopefully that's the end of it. One last
question, is there a way to set the IDE to always use IE? I remember
seeing an option for that in VS 2k3, but I don't see it in the web
project settings for VS 2k5.
 
S

saturday

Thanks much, you've been a *great* help. Yeah changing the browser was
the last thing to do on my list, but my coworker insisted, and to my
surprise, it worked...go figure.

Thanks again!
 

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

Top