AsafSavich AsafSavich - 1 year ago 73
HTML Question

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."Filter" and "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"/>

If I press the "filter" button it works awesome.

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


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.


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 :)

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download