ajax and asp.net OnClick clash - asp.net

I have a OnClick even on a image button and also a AJAX modualPopupExtender (from the ajax toolkit) the problem i have is that when i have the ModalPopupExtender acting on the image button it doesent fire the onClick event on the imageButton hers the code i have:
<ItemTemplate>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="btnCancel"
TargetControlID="Image1" PopupControlID="Panel1" BackgroundCssClass="ModalPopupBG">
</asp:ModalPopupExtender>
<asp:ImageButton ID="Image1" OnClick="ImageButton_Click" runat="server" ImageUrl="~/images/Upload-icon.png" />
</ItemTemplate>
when i have this code the panel does popup but doesn't fire the onClick event, if i take out the ajax extender it fires the onclick event is they any way i can have both?
Thanks in advance.

Put another button with a CSS class so it doesn't show on the page (or style="display:none;" don't use visible=false or it won't work).
Then make the TargetControlID of your Modal Popup Extender to be your fake button.
Now you can handle the Click event of the ImageButton normally in your code behind, after doing the code that you want, call
ModalPopupExtender1.Show()
to show the popup.

Related

ASP.NET Webforms OnClientClick without enter submission

I have the following command button:
<asp:Button Text="Insert Value" UseSubmitBehavior="false" runat="server" OnClientClick="return Confirmation.value('insert');" CommandName="Insert" />
I am using UseSubmitBehavior="false" to prevent ASP.Net page enter key causing post back
I do not want to listen to the enter keyCode via javascript because enter is used to submit non-webform elements not related to the form
Apparently, when using a Command and UseSubmitBehavior="false" then OnClientClick doesnt work. If I turn on submit behavior it works as expected but then hitting enter on the page automatically tries to click the button.
I prefer not to listen for the click event in Jquery or in javascript, and prefer a webform solution. Possible a better way of prevent enter from submitting the form or a way for OnClientClick to work properly with no submit behavior
You may need to use Panel and keep all your form inside Panel Tag and set the DefaultButton value of Panel to Button. Like Below:
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
// other form elements
<asp:Button Text="Insert Value" ID="Button1" runat="server" OnClientClick="return Confirmation.value('insert');" />
</asp:Panel>

Button not triggering function asp.net

I have a form with only a file upload control and 2 gridviews, for each grid view we have an add button and a save button for the whole page:
So the first button for gridview1 works fine but the other 2 buttons are not even displaying the msgbox inside the function, I tried adding CausesValidation=false but that didn't changed anything.
What could be wrong?
<asp:FileUpload ID="fileup" runat="server" />
<asp:Button runat="server" Text=" + Add" ID="btnGrid2"/>
<asp:Button runat="server" Text="Save" ID="btnSave"/>
Change your code from
<asp:Button runat="server" Text="Save" ID="btnSave"/>
To
<asp:Button runat="server" Text="Save" ID="btnSave" onclick="btnSave_Click"/>
That is happening because you've copied whole event from another page and because of that actual event in aspx page is not generated.
Visual Studio gives facility of generating events automatically.
Just Place a control in your page -> Go to Control's Properties -> Navigate to events. -> Find OnClick and duble click there. It will generate your buttonclick event automatically in aspx.vb code behind file.
Or you can simply put a button in your design page and then by clicking on it will also generate buttonclick event automatically.
Hope it helps.

ModalPopupExtender and dropdownlist

I have the following code on my page:
<asp:ModalPopupExtender ID="mpLabelCheck" PopupControlID="pnlModal" TargetControlID="lstCategory"
OkControlID="btnOK" runat="server" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel id="pnlModal" CssClass="modalPopup" runat="server">
<p>Please make sure all data is entered before continuing.</p>
<p><asp:Button ID="btnOK" Text="OK" runat="server" /></p>
</asp:Panel>
The target control ID is a dropdownList. What happens is any interaction with the dropdownlist triggers the popup. I'd like to wait until the user makes a selection, then conditionally show the popup based on the result of another method.
Any thoughts on how I can accomplish this?
Use dummy hidden control as target for extender and show it in server code with Show method call

FileUpload, UpdatePanel and ModalPopupExtender

I am trying to use a FileUpload control in a ModalPopupExtender in an UpdatePanel.
I have set a trigger for my Upload button, so that it does a full postback.
What happens is that after the full postback, all the ModalPopupExtenders that I have in the page show up one after the other at the bottom of my page, rah
I've tried using the AsyncFileUpload control, but have not been able to get the UploadEvent to fire, have tried everything I could find in Google. Decided to stick with the FileUpload control.
<ajaxToolkit:ModalPopupExtender ID="MPEBannerImage" runat="server" TargetControlID="btnBannerImage" PopupControlID="pnlBannerImage" Y="200">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlBannerImage" runat="server" Width="530px" >
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:ImageButton ImageUrl="btn-UploadFile.png"
ID="btnUpload" runat="server" OnClick="btnUpload_Click" />
</asp:Panel>

Detecting Enter in TextBox ASP.NET no JavaScript Please

Basically I have a Search Text Box with a LinkButton Control on which the click event is fired. now what i want is when the user type keywords and press enter the Click event got fired.
So No Javascript Only ASP.NET With VB.NET v2.0
Sincerely
Rajeev
Rajeev_rsd#hotmail.com
Create a Panel that contains both the TextBox and LinkButton. The Panel has a property called DefaultButton, set DefaultButton equal to the ID of the LinkButton.
<asp:Panel id="panel" runat="server" DefaultButton="linkButton">
<asp:TextBox id="search" runat="server"/>
<asp:LinkButton id="linkButton" runat="server"/>
</asp:Panel>
Can you not just use AutoPostback on the textbox?

Resources