OnClick event for ImageMap never never being invoked - c#

I have an ImageMap control in an ascx file of mine. I'm trying to make something happen when the user clicks on an area in the map, but the page just posts back without my "imageMap_Click" event handler never being invoked. Suggestions?
<asp:ImageMap ID="imageMap" runat="server" ImageUrl="~/images/MapImages/map.jpg" HotSpotMode="PostBack" OnClick="imageMap_Click">
My imageMap_Click looks like this, just to see if it's invoked at all:
protected void imageMap_Click(object sender, ImageMapEventArgs e)
{
throw new NotImplementedException();
}

I've found it already. It was due to the control having viewstate disabled, like this:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MapControl.ascx.cs"
Inherits="XXX.MapControl" EnableViewState="false" %>
I don't understand why. Anyone care to tell me?

Just from the docs, shouldn't your image map have the different locations in it for the click mapping?
eg:
<asp:ImageMap ID="SaturnImage"
ImageUrl="~/saturn.PNG"
runat="server" OnClick="SaturnImage_Click">
<asp:CircleHotSpot AlternateText="planet" HotSpotMode=PostBack
PostBackValue="planet" Radius=40 X=100 Y=100 />
<asp:CircleHotSpot HotSpotMode=Inactive
Radius=60 X=100 Y=100 />
<asp:CircleHotSpot AlternateText="rings" HotSpotMode=PostBack
PostBackValue="rings" Radius=80 X=100 Y=100 />
</asp:ImageMap>
Because I'm assuming with ImageMap that when you click on it it only does the postback if you click on a part which is set up to be clicked. It shouldn't generated a clicked event if none of the mapped parts are clicked on.

Related

Skip to Content Link

I am trying to put a Skip to Content link within my web application, but am having some issues.
Currently I have
<asp:LinkButton id="linkSkiptoContent" runat="server" OnClick="linkSKipToContent" Text="Skip to Content"></asp:LinkButton>
within the asp page
and an onClick event receiver
protected void linkSkipToContent_Click(object sender, EvenArgs e){
checkbox.Focus();
}
I am trying to avoid javascript because users have the option to disable it, which would render the link useless. And I know the checkbox.Focus() works properly, since I stuck it in the Page_Load() method and that worked at intented. However, what happens is clicking the link causes it to be focused after the onClick event completes.
Just print an anchor:
<a name="content" />
And link to it:
Go to content
Don't need JS or serverside stuff for that.

asp.net Button OnClick event not firing

I have problem in asp.net button control.
I define a button in form, onclick event of button is not firing when I click on the button.
<asp:Button ID="btn_QuaSave" runat="server" Text="SAVE" OnClick="btn_QuaSave_Click" />
protected void btn_QuaSave_Click(object sender, EventArgs e)
{
}
Because your button is in control it could be that there is a validation from another control that don't allow the button to submit.
The result in my case was to add CausesValidation property to the button:
<asp:Button ID="btn_QuaSave" runat="server" Text="SAVE" OnClick="btn_QuaSave_Click" CausesValidation="False"/>
Have you copied this method from other page/application ? if yes then it will not work, So you need to delete the event and event name assigned to the button then go to design and go to button even properties go to onClick event double click next to it, it will generate event and it automatically assigns event name to the button.
this should work
I had the same problem, my aspnet button's click was not firing. It turns out that some where on other part of the page has an input with html "required" attribute on.
This might be sound strange, but once I remove the required attribute, the button just works normally.
If you are using updatepanel on onclick event, this may happen.
Use 'EnableEventValidation="false"' in your page markup like this :
<%# Page Language="C#" MasterPageFile="~/ars_home.master" AutoEventWireup="true" CodeFile="Transaction_Window.aspx.cs" Inherits="Transaction_Window" EnableEventValidation="false" %>
Hope this helps
I had a similar issue and none of the answers worked for me. Maybe someone finds my solution helpful. In case you do not mind submitting on button click, only attaching to click event setting UseSubmitBehavior="false" may be worth trying.
In my case I put required="required" inside CKEditor control.
Removing this attribute fixed the issue.
Before
<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server" required="required"></CKEditor:CKEditorControl>
After
<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server"></CKEditor:CKEditorControl>
i had the same problem did all changed the button and all above mentioned methods then I did a simple thing I was using two forms on a single page and form with in the form so I removed one and it worked :)
Try to Clean your solution and then try once again.
It will definitely work. Because every thing in code seems to be ok.
Go through this link for cleaning solution>
http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/e53aab69-75b9-434a-bde3-74ca0865c165/
Try to go into Design mode in Visual Studio, locate the button and double click the button that should setup the event. Otherwise once the button is selected in Design more, go to the properties and try setting it from there.
Add validation groups for your validator elements. This allows you distinguish between different groups which to include in validation. Add validation group also to your submit button
in my case:
make sure not exist any form element in your page other than top main form,
this cause events not fired
If the asp button is inside tag then also the Click event will not raise.
Hope it's useful to some one.
In the case of nesting the LinkButton within a Repeater you must using something similar to the following:
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="MyUpdate">LinkButton</asp:LinkButton>
protected void Repeater1_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("MyUpdate"))
{
// some code
}
}
If it's throwing no error but still not firing the click event when you click the submit button, try to add action="YourPage.aspx" to your form.
Even i had two forms one for desktop view and other for mobile view , Removed one formed worked for me . I dint knew asp.page should have only one form.
Try this onserverclick
<button id ="DemoButton" runat="server" onserverclick="button_Click">Login</button>

PostBack Events Not Firing form Controls a bug from visual studio?

I think i'm missing something. What is the proper way to display an html div, for example, if the actual condition is met using Page_Onload + isPostBack + asp:button as a trigger for the event as following:
Page_Load -> Click event fired
Page load - element(a dynamically generted string for multiple table rows in this case)
status hidden
Client click submit button:
Element toggled to visible.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
nothing yet
}
else
{
suppose to check on client event handle by asp button
}
}
// So here is the event fired by client
protected void imgButSbmt_Click(object sender, ImageClickEventArgs e)
{
initializeReportTable();
}
and suddenly while trying to make sure I am correct with this argument,
I could see that imgButSbmt_Click is not "hitting" (with break Point attached while in debugging mode).
So first... I could note at this time that it's an unusual behavior (and while I am writing this question supposbly related to all my projects, this one was not firing at all events, so I solved it by deleting the solution file as I was writing this post).
So now, it does work.
BUT... this time (while solution is not yet to be Created) I re-opened my website "project" via File-Open-Website.
Hit F5 ...break Point works fine in red color.. no explanation marks this time. However, all events from the button & Drop down List that are configured to AutoPostBack
protected void DDL_Month(object sender, EventArgs e)
{
initializeReportTable();
}
were not firing. All events except for Page_Load are firing now. After checking again it does fire but only on the second time!
What is happening here?
I remembered some readings I came across awhile ago that said I should check the autoeventwireup and make sure it is set to true (it's the default I think).
So these are the page directives:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Here is an example of a control DropDownList + imgButton within a table:
<td>
<asp:DropDownList ID="DDL_Month" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL_Month"></asp:DropDownList>
</td>
<td>
<asp:ImageButton ID="imgButSbmt" ImageUrl="images/sendreq.png"
runat="server" Height="25px" OnClick="imgButSbmt_Click"
style="margin-right: 0px; border-width:" />
</td>
as sugested by #JonH , and as a solution i've already had to use in some other even bugier scenario
if you're experiencing any UCB (un identified Code Behavior)...
just do as follow
1) open a new folder as a new home for the project Work-folder
2) copy all sub folders from The Buggy project, such as images, js etc'
3) Create a new webSite / any other application you had unusual problems with
then just apply all references needed for the application , copy codes to newly created .cs/vb/aspx
accordingly , use exisiting items (your other classes that are in separeted files)
and now you're ready to continue working...
the bugs should be behind you by now
just don't forget to delete the old project and any solutions files associated with it.
hope it will help some of other fresh developers who also encounterd the U.C.B Phenomenon

Is there way I can lazy load an accordion pane's datasource?

I'm trying to lazy load the content datasource of an accordion pane. So in other words, when the pane is opened, it will bind the datasource. I'm unable to find an event that I can use to fire the if (source == null) LoadMe(); logic.
I know at least a hundred people out there have done this before. Any ideas would be helpful. TIA
ok i got it working. Im not entirely happy with it, but this is what I got:
Each header has a link button that I sized to fill the entire area, essentially making that area clickable:
<ajaxToolkit:AccordionPane ID="acpInReview" runat="server">
<Header>
<asp:LinkButton runat="server" Width="100%" Height="25" CssClass="SectionLinkButtons" CommandName="LoadInReview">In Review</asp:LinkButton>
</Header>
As you see, it has an associated command with it. in the parent accordion, I set the event handler that fires when a command is detected within the template:
<ajaxToolkit:Accordion runat="server" ID="accMainNav" HeaderCssClass="AccordionSection"
CssClass="AccordionMainNav" ContentCssClass="AccordionContent"
RequireOpenedPane="False" SelectedIndex="-1"
OnItemCommand="accMainNav_OnItemCommand" ClientIDMode="Static">
<Panes>
...
Then in the code behind, the handler reads the command and does it's thing:
protected void accMainNav_OnItemCommand(object sender, CommandEventArgs e)
{
switch(e.CommandName)
{
case "LoadAwaitingControllerApproval":
LoadAwaitingControllerApproval();
break;
case "LoadInReview":
LoadInReview();
break;
case "LoadAwaitingFinalization":
LoadAwaitingFinalization();
break;
}
}
I also wrapped the whole thing in an updatepanel so that i could use the updateprogress control. So essentially what happens is the link button gets clicked when you click on a header which fires a command. That command is routed to the event handler which binds the datasource. Since it is in an updatepanel, it happens asynchronously and I use the updateprogress control to display a loading indicator. I could improve it by backing the link button with a div that covers the whole area then give that div an onclick event that causes a postback. But for now, this works.

C# - ASP.NET Button click event not working

I have an ASP.NET (C#) page with some 3rd party controls, some ajaxy stuff and some normal ASP.NET Button controls.
The Button click events do not fire when clicked.
Double-clicking the button in design mode in VS 2008 switches to the code-behind but doesn't create the event handler.
Creating the event handler manually doesn't help.
The whole page is too big to include here, but this is the top bit:
<%# Page Language="C#" MasterPageFile="~/basewidepage2.master" AutoEventWireup="true" EnableEventValidation="false" CodeFile="CompanyCompliance.aspx.cs" Inherits="CompanyCompliancePage" Title="3DSS" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%# Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="cc2" %>
<%# Register Src="usercontrols/CalendarEx.ascx" TagName="CalendarEx" TagPrefix="uc2" %>
<%# MasterType VirtualPath="~/basewidepage2.master" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceholder1" runat="Server">
<script type="text/javascript">
// a bunch of function declarations
</script>
...and my button declaration on the page:
<asp:Button ID="LicenseCsvButton" runat="server" Text="Export to CSV" OnClick="LicenseCsvButton_Click" />
...and the code-behind:
protected void LicenseCsvButton_Click(object sender, EventArgs e)
{
// get data
CompanyCompliance cc = new CompanyCompliance(Master.theCompany.ID);
DataTable dt = cc.BusinessLicenses.Tables[0];
// send to browser as download
Tools.SendTableAsCsvToBrowser(Response, dt, "LicenseData");
}
Any ideas? could it be the ajax or something? Maybe the 3rd party "obout" grid control?
Update:
I did fix this a month or two ago, so I came back to this question to answer it for posterity but couldn't remember exactly how I fixed it! (Curse you, old age!) I had some limited success by replacing some of the ASP.NET AJAX controls with jQuery UI ones but I think the real solution was that one of the properties in the one of the tags was pointing to a control that no longer existed.
If you're in this same situation, try that and let me know what works in the comments and I'll post the correct answer.
During debugging, check the CausesValidation property of your button. For some reason, one of my pages had a button defaulting to "True." When I explicitly set it to "False" everything worked.
I know that this should be resolved by now, but just to share - I just had a similar issue. In my case, the problem was that I had a RequiredFieldValidator in a page, that wasn't visible because it was part of a popup. That validator was supposed to be invoked only when clicking its related "Save" button, but since I didn't have any ValidationGroup set, it would prevent the page to submit for any clicked button. Adding a ValidationGroup to the right button resolved the issue.
Experienced the same issue recently - cause was eventually determined to be that the button was disabled by a juavascript method onbeforesubmit (designed to prevent multiple submissions), and unfortunately web forms appears to check the enabled state of the button before it allows the codebehind event to trigger.
I had this problem just now and it was caused by another control having an AutoPostBack="true" which would submit the form before the button had a chance to submit the form to trigger the click event.
Change
CodeFile="CompanyCompliance.aspx.cs"
to
CodeBehind="CompanyCompliance.aspx.cs"
Related question: CodeFile vs CodeBehind
The inherits directive seems to point to a non-existant type.
Take a look in the code behind file of the CompanyCompliance page - ("CompanyCompliance.aspx.cs").
you should find the correct namespace and something like "public partial class xxx" where xxx is the name of the class which should correspond with your inherits directive. maybe you have to fully qualify the name as TJB already stated.
I had a similar issue, and it was really tricky. I recently migrated a VS 2005 ASP.NET 2.0 web forms app to VS 2010 ASP.NET 4.0.
It was difficult to setup and buggy as expected, but the issue of buttons not firing the click event was getting on my nerves.
In the end, it was as simple as not declaring a submit action in the site.master form. I changed:
<FORM runat="server" name="MainForm" method="post" action="Default.aspx" id="m_mainForm" enctype="multipart/form-data">
to
<FORM runat="server" name="MainForm" method="post" id="m_mainForm" enctype="multipart/form-data">
Boom. Problem solved. I hope it saves days of troubleshooting to someone. Sadly, I couldn't find anything about it on the internet by myself.
I had this problem I have changed the Button property "UseSubmitBehavior"=false. Now it is working.
For future answer seekers : If you are assigning the click handler in code behind, make sure that it is not inside an IsPostBack == false check :
void Page_Load (object oSender, EventArgs oEventArgs)
{
if (IsPostBack == false)
{
oButton += new EventHandler(oButton_Click); // does not work
}
oButton += new EventHandler(oButton_Click); // does work
}

Categories