简体   繁体   中英

ASP.Net Button not raising postback

I've a simple page in one of our web applications, which has the following markup:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NewUpload.aspx.cs" Inherits="Mass_Upload.NewUpload" MasterPageFile="~/Master" Title="Document Mass Upload" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="Stylesheet" type="text/css" href="./../CSS/ScrollingTable.css" />
    <script type="text/javascript" src="../Help/HelpPopup.js" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CenterH1" runat="server">
    Document Mass Upload <a href="javascript:loadHelpVid(5)"><img style="Border:None;" src="../Help/help_icon.gif" /></a>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="CenterBody" runat="server">
    <h3>Add New Upload</h3>
    <table class="list">
        <tr>
            <td class="label" style="text-align:right;">Local File:</td>
            <td class="normal">
                <asp:FileUpload ID="fuFilename" runat="server" Width="405" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Text="*"
                            ErrorMessage="A file to upload is required"
                            Display="Dynamic"
                            ControlToValidate="fuFilename"
                            ValidationGroup="DocumentUpload"
                            runat="server" />
            </td>
        </tr>
        <tr>
            <td class="label" style="text-align:right;">Document Description:</td>
            <td class="normal">
                <asp:TextBox ID="txtDescription" runat="server" Width="405" MaxLength="50" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Text="*"
                            ErrorMessage="Document Description is a required field"
                            Display="Dynamic"
                            ControlToValidate="txtDescription"
                            ValidationGroup="DocumentUpload"
                            runat="server" />
            </td>
        </tr>
        <tr>
            <td class="label" style="text-align:right;">Document Type:</td>
            <td class="normal">
                <asp:DropDownList ID="ddDocType" runat="server" Width="405"/>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Text="*"
                            ErrorMessage="Document Type is a required field"
                            Display="Dynamic"
                            ControlToValidate="ddDocType"
                            ValidationGroup="DocumentUpload"
                            runat="server" />
            </td>
        </tr>
        <tr>
            <td class="label" style="vertical-align:top;text-align:right;">Customer Types:</td>
            <td class="normal">
                <asp:Label ID="lblSingleCustomer" Text="Specific Code:" runat="server" /><asp:TextBox ID="txtSingleCustomer" runat="server" Width="100px" /><br />
                <asp:CheckBoxList ID="cblCustomerTypes" runat="server" Width="405px" RepeatDirection="Horizontal" RepeatColumns="5" RepeatLayout="Table" CellPadding="10" CellSpacing="0" />
            </td>
        </tr>
        <tr>
            <td class="normal" colspan="2">&nbsp;</td>
        </tr>
        <tr>
            <td class="normal" colspan="2"><asp:Label ID="lblError" runat="server" Text="" ForeColor="Red"/></td>
        </tr>
        <tr>
            <td class="normal" colspan="2">
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="BtnCancel_Click" CssClass="medium" />
                <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="BtnUpload_Click" CssClass="medium" />
            </td>
        </tr>
    </table>
</asp:Content>

It USED to work fine, but now, and without apparent change to code/design, both the "Upload" and "Cancel" buttons no longer work.

Putting a breakpoint in the codebehind's Page_Load() method shows that it is only called when the page is initially loaded, and not when the button is pressed. Similarly, putting a breakpoint in the "BtnUpload_Click" event shows it is never called.

This is now not working both on my own development machine AND on the client's server (both when browsing to the servers page from my machine AND from the server itself).

It's important to stress that, between this working and it now not working, I am 90% sure nothing has changed in regards to the code.

Any help would be greatly appreciated, as the customer is rightly anxious - and i'm clueless as to what's causing it!


EDIT #1

Here's the codebehind for one of the buttons:

protected void BtnUpload_Click(object sender, EventArgs e)
    {
        if (DataAccess.CheckIfMassUploadAlreadyExists(fuFilename.FileName))
        {
            lblError.Text = "A file with the specified name already exists within the system.";
            return;
        }
        else
        {
            try
            {
                UploadFile();
            }
            catch(Exception ex)
            {
                lblError.Text = ex.Message;// +"\nUsername:" + System.Web.HttpContext.Current.User.Identity.Name;
                return;
            }
        }
    }

.

Here's the reason.. and it's a really annoying reason too!

THIS:

<script type="text/javascript" src="../Help/HelpPopup.js" />

Should be THIS:

<script type="text/javascript" src="../Help/HelpPopup.js"></script>

Whoever decided the script tag needs to be treated differently to every other HTML tag, needs to be locked in a room with Justin Bieber.

First off all you should check your Validators and perhabs, comment them out for a test.

Is it possible that there are JavaScript-Errors showing on your page? An ASP-Button is calling a JavaScript-Funktion (WebForm_DoPostBackWithOptions), if there is a JavaScript-Error "before" this line, sometimes you can't press a button.

At the risk of being down voted for posting an answer to the title question which does not appear to be the OP's problem... I will offer this suggestion which fixed my similar problem:

<body  background="images/GlobeBg.png" bgproperties="fixed">
</body>

Problem is, 'bgproperties' is NOT a valid attribute name even though some guys on the internet said it was. Other than an unnoticed squiggle underline in VWD 2008 Express, no error was emitted and the page otherwise looked normal. Simply, the update button and other input controls didn't work.

apparently a client side "return false" is preventing the callback, this could be one of two reasons:

1-the validators always return not valid
2-some client script being called on the button returns false;

对我而言,原因是同一页面上另一个视图上的验证器被解雇,因为它属于同一验证组。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM