简体   繁体   中英

ASP - OnServerClick Doesn't work properly

I'm using ASP.NET with C# 4.0.
My problem is that I want only one button to activate a certain method on server.
What do i mean? I'm glad you asked.
I have 2 buttons. “过滤器”和“ FetchEvents”
Any my aspx code is:

 <form id="form2" runat="server">
     <div class="box-generic">
         <div class="form-group well" style="">
            <input type="submit" name="button_filter" value="filter" class="btn btn-primary" />
            <input type="button" id="all_events_button" name="all_events_button" value="All Events CSV" class="btn btn-primary" OnServerClick="downloadAllEvents" runat="server"/>  
         </div>
     </div>
 </form>

If I press the "filter" button it works awesome.
Whenever I press the "All Events CSV" button, it works great.

Scenario

1. Clicking on All Events. (Activates the all events button normally)
2. Clicking on Filter.

downloadAllEvents() Method is being activated. BAD BAD BAD

And the weirdest part about it is that this method will be activated through filter only after it has been activated through AllEvents.

EDIT:

I'm currently checking inside the method that the call didn't came from the filter button.
not a pretty sight.

Haven't found someone with the same problem.
Thanks in advance :)

I did a below sample page, and its working perfectly... can you POST the full page ... ?

Try this code and tell me what exactly is happening:

<%@ Page Language="C#" AutoEventWireup="true" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Am Load<br/>");
    }

    protected void downloadAllEvents(object sender, EventArgs e)
    {
        Response.Write("Am Download");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form2" runat="server">
        <div class="box-generic">
            <div class="form-group well" style="">
                <input type="text" name="x" />
                <input type="submit" name="button_filter" value="filter" class="btn btn-primary" />
                <input type="button" id="all_events_button" name="all_events_button" value="All Events CSV" class="btn btn-primary" onserverclick="downloadAllEvents" runat="server" />
            </div>
        </div>
    </form>
</body>
</html>

Not the answer I was hoping for, BUT it works and it works good. (Bugless)
In my downloadAllEvents() I check who sent the post request and I deny the post request from anyone who is not all_events_button

By doing so i transfer the responsibility from the sender to the listener. If anyone has better answer please provide it.

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