Button on MasterPage Does Nothing

J

Jonathan Wood

Does anyone know of any reason a button on a master page would have no
effect?

I have a complex HTML page that I'm converting to ASP.NET, and acknowledge I
could have something odd that is affecting this.

But I'm stuck. My handler is in C# code and the code looks right. But
absolutely nothing happens when I click the button.

protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = "Button1_Click";
}


<p>
<asp:Button runat="server" Text="Button" id="Button1"
OnClick="Button1_Click" /></p>

Thanks for any tips.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Jonathan said:
Does anyone know of any reason a button on a master page would have no
effect?

I have a complex HTML page that I'm converting to ASP.NET, and
acknowledge I could have something odd that is affecting this.

But I'm stuck. My handler is in C# code and the code looks right. But
absolutely nothing happens when I click the button.

protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = "Button1_Click";
}


<p>
<asp:Button runat="server" Text="Button" id="Button1"
OnClick="Button1_Click" /></p>

Thanks for any tips.

"Nothing" never happens. What exactly happens when you click the button?

Does the button look like it reacts to the mouse click? I.e. does it's
appearence change when you press the mouse button?

Does the page do a postback or not when you click the button?
 
J

Jonathan Wood

Göran,
"Nothing" never happens. What exactly happens when you click the button?
Nothing.

Does the button look like it reacts to the mouse click? I.e. does it's
appearence change when you press the mouse button?

If I use a regular button, then Windows redraws it to appear pressed when I
click it. If I use a bitmap button, the cursor changes to the hand pointer.
Both controls also take the input focus when clicked. But I can detect
absolutely nothing happening in response to a click.
Does the page do a postback or not when you click the button?

Well if it did a postback, that would be something. There is no indication
that it is doing a postback. The page doesn't flicker, it doesn't reset to
the top of the page. And the button text does not change in response to my
code.

Jonathan
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Jonathan said:
Göran,


Nothing.

If that really is the case, then you have placed some other, invisible,
element on top of the button so that it's impossible to click on.
If I use a regular button, then Windows redraws it to appear pressed
when I click it.

That's not nothing. Something is actually happening when you click the
button. That means that it's actually possible to click on the button,
and that the button reacts to the click.
If I use a bitmap button, the cursor changes to the
hand pointer. Both controls also take the input focus when clicked. But
I can detect absolutely nothing happening in response to a click.

That doesn't mean that nothing happens. The button reacts to the click,
and that most likely means that the process of posting the form is
started. I don't know yet why it doesn't succeed, but there is probably
something in your page that stops it.

Do you have any onsubmit event on the form?
 
D

David R. Longnecker

I've seen this happen a few times... the Inherits string at the top of the
master page doesn't match the code behind page for the master page:

on the .Master page:

'**********************************

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="TestMasterPage.master.cs"
Inherits="SandBox.TestMasterPage" %>

'**********************************

On the .Master.cs page:

'**********************************

namespace SandBox // <------ HERE
{
public partial class TestMasterPage : System.Web.UI.MasterPage //
<---- HERE
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}

'**********************************

Make sure they match. If they don't, the OnClick will never be seen and
the button will "press down", but since it doesn't see an associated event
in the partial class, it just keeps on going (and won't throw an error =( ).

-dl
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

David said:
I've seen this happen a few times... the Inherits string at the top of
the master page doesn't match the code behind page for the master page:

on the .Master page:

'**********************************

<%@ Master Language="C#" AutoEventWireup="true"
CodeBehind="TestMasterPage.master.cs" Inherits="SandBox.TestMasterPage" %>

'**********************************

On the .Master.cs page:

'**********************************

namespace SandBox // <------ HERE
{
public partial class TestMasterPage : System.Web.UI.MasterPage //
<---- HERE
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}

'**********************************

Make sure they match. If they don't, the OnClick will never be seen and
the button will "press down", but since it doesn't see an associated
event in the partial class, it just keeps on going (and won't throw an
error =( ).

If that was the problem, the button would still cause a postback, but
according to Jonathan that doesn't happen.
 
J

Jonathan Wood

Göran,
That's not nothing. Something is actually happening when you click the
button. That means that it's actually possible to click on the button, and
that the button reacts to the click.

Yes, the button works at the Windows-level. That is, the code Windows uses
to handle standard buttons is working, and the button is not disabled.

That's fine if you want to call that something but, with respect to code
running in response to that event, I see no indication of that.
Do you have any onsubmit event on the form?

No.

Jonathan
 
J

Jonathan Wood

BTW, of course it's possible something is happening in response to the
button click event, I'm only saying there is no indication of that.

If this were a desktop application, I'd popup a message. If I could run the
site under Visual Studio (I can't), I'd set a break point. I'm just using
Expression Web for this and, without Intellisense, I just don't know ASP.NET
well enough to figure out how to verify the handler never gets called other
than there is no sign of a postback and my handler code that changes the
button's text appears to have no effect.

Jonathan
 
J

Jonathan Wood

Here's the header in my default.aspx:

<%@ Page Language="C#" masterpagefile="cygnus.master" title="Cygnus Hex
Editor" %>
<%@ MasterType VirtualPath = "cygnus.master" %>

And here's the header in my cygnus.master:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<%@ Master Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Diagnostics" %>

The buttons in question on defined on the master page, and the handler is
defined as server-side script on the master page (no separate code file).

So that doesn't appear to be the issue unless I'm missing something.

Jonathan
 
G

Guest

I have the same (or similar) issue. The button in question is not on a master
page but the symptom is the same. The button appears to be getting clicked
but no code executes (oninit, onload, onclick, etc). Other buttons on the
page work fine.

Run the same code in VS on a machine running the same version of everything
(Windows, IE, VS, IIS, SP's, etc.) and the button works as expected. If I
publish the website on my machine, it runs correctly on other machines but
not on mine.

My solution is to not click the button on my machine. ;~o

Jonathan Wood said:
BTW, of course it's possible something is happening in response to the
button click event, I'm only saying there is no indication of that.

If this were a desktop application, I'd popup a message. If I could run the
site under Visual Studio (I can't), I'd set a break point. I'm just using
Expression Web for this and, without Intellisense, I just don't know ASP.NET
well enough to figure out how to verify the handler never gets called other
than there is no sign of a postback and my handler code that changes the
button's text appears to have no effect.

Jonathan
 
G

Guest

Sorry about the last message, I forgot to add the real reason for the
problem. In my case, it was due to the fact that the POSTDATA size was too
large (app error in eventvwr). The reason it appeared to work on one machine
and not another was that the file being uploaded from my machine was larger
than the file being uploaded on the other machines.

Jonathan Wood said:
BTW, of course it's possible something is happening in response to the
button click event, I'm only saying there is no indication of that.

If this were a desktop application, I'd popup a message. If I could run the
site under Visual Studio (I can't), I'd set a break point. I'm just using
Expression Web for this and, without Intellisense, I just don't know ASP.NET
well enough to figure out how to verify the handler never gets called other
than there is no sign of a postback and my handler code that changes the
button's text appears to have no effect.

Jonathan
 

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

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top