It seems that sometimes (but not always) my button click event is being fired twice. The fact that it seems to happen sometimes but not always is really puzzling me. i already try button visible false or disable functionality. please help. Here is my button :
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" style="background-color:#e3e6ea; padding:5px; color:#000000; font-weight:bold;" ValidationGroup="Validate" />
Use the OnClientClick and UseSubmitBehavior properties of the button control you can prevent the double click , change your asp.net code as follows :
<asp:Button ID="btnSubmit" runat="server"
Text="Submit"
OnClick="btnSubmit_Click"
OnClientClick="this.disabled=true;"
UseSubmitBehavior="false"
style="background-color:#e3e6ea;
padding:5px;
color:#000000; font-weight:bold;" ValidationGroup="Validate" />
You need to add OnClientClick="this.disabled=true;" and UseSubmitBehavior="false" to your button control
i think you have used "btnSubmit_Click" event twice in your code, please check your code ,i hope your problem will solve.
Related
I have three textbox and one button. Here is my problem:
I use autopostback="true" in textbox, i entered some value and after first click of the button is not working. Then i click again, second click is working. I looked on F12 developer tool on Browser, there is no an error. When i set autopostback="false" than button click is working without any problem.
I would like to use autopostback="true" because it helps me. I think there is a focus problem because when i click out of textbox and than click on the button, button works with autopostback="true"
Do you have any idea for solution of this problem. All controls are working server-side.
<asp:Textbox ID="Name" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="Surname" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="City" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" ValidationGroup="myval"></asp:Button>
I found a solution. It's not stable solution but however it's working. I hope it helps you too. My solution is:
<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" OnClientClick="return true;" ValidationGroup="myval"></asp:Button>
I added OnClientClick="return true;" and button click is working on first click now.
If you have better solution waiting for your response.
I have defined form action in my asp page and with in form, I have defined the Textbox OnTextChanged. but when I type any thing on Textbox and click on tap to move next.. automatically instead of calling OnTextChanged ..my form action calls..
my code is below
<form id="WebToLead" action="https://url" method="POST" runat="server">
<asp:TextBox id="a" name="a" maxlength="10" runat="server" OnTextChanged="a_TextChanged" AutoPostBack="true" />
// some more textbox
<asp:Button ID="Button2" Text="Click" width="50px" runat="server" OnClick="Button2_Click" />
</form>
Means it action should be triggered on button2_click but it does when i type anything on aand tap to other fields
Ensure you have viewstate enabled for this to work, otherwise Asp.Net has no way of knowing whether the control's value has changed.
AutoPostBack is enabled thats why it is posting the form back to server. Remove it or disable it. It should work after that.
I am using a button as a link because when the button is pressed it opens a popup of In Line HTML using Javascript (http://www.enthropia.com/labs/ibox/):
<asp:Button ID="searchButton" runat="server" Text="Search Stories" OnClick="searchButton_Click" />
However, this prevents the OnClick C# from executing when I press the button. How do I fix this?
I suggest you this code
<a href="#inner_content" rel="ibox&width=800&height=400" title="Search Non Scrum Stories">
</a>
<asp:Button ID="searchButton" runat="server" Text="Search Stories" OnClick="searchButton_Click" />
David you must separate html link and button (it's not xaml)
Alternatively, you can use LinkButton - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx
Example (from the linked documentation):
<asp:LinkButton id="LinkButton1"
Text="Click Me"
Font-Names="Verdana"
Font-Size="14pt"
OnClick="LinkButton_Click"
runat="server"/>
separate the tags and put your button in as a submit button or you can do something like:
<form action="ur_popup_page" onsumit="javascriptsunction()">
<asp:Button type="submit" id="searchbutton"/>
</form>
im creating the form include below code :
<asp:TextBox ID="txtPhone" required="required" runat="server" placeholder="Phone No. (eg. 999)"
CssClass="glowStyle"></asp:TextBox>
<br />
<asp:Button ID="btnAddDriver" Text="Add" runat="server" CssClass="button" />
<br />
<asp:Button ID="btnCnclAddDriver" Text="Clear" runat="server"
CssClass="cancelbutton" onclick="btnCnclAddDriver_Click" />
</form>
when i click the "Clear" button, the required (html5) still show up.
how to disable it for Clear button only.
Add formnovalidate attribute to your cancel/clear button.
Here you can find some more information about this attribute.
Do you actually require a server control to cancel ? A simple <input type="reset"> or a small javascript code can do the job in most situations.
If not, simple add CauseValidation="false" to your button :
<asp:Button ID="btnCnclAddDriver" CauseValidation="false" Text="Clear" runat="server"
CssClass="cancelbutton" onclick="btnCnclAddDriver_Click" />
(remove suggestion as it applies to asp.net validation)
You can set the autopostback option for btnCnclAddDriver button to False. And execute your server side code (btnCnclAddDriver_Click) by Ajax.
You can clear your TextBox(s) with javascript (jQuery) :
$('txtPhone').val('');
Or Javascript :
function name()
{
document.getElementById('txtPhone').value = "";
}
Hope this help.
I am hoping that someone can help shed some light on this issue I've been struggling over for the last couple of days. I have been using the AJAX Toolkit ModalPopupExtender outside of ListViews perfectly fine, but for some reason I can't seem to wrap my head around why this code is not working inside of a ListView item template.
Basically, what I am trying to achive is: a user is presented with some rows of data via the ListView in which each row displays a LinkButton with the text "Remove". I want the user to be able to click on this link, and a modal dialog box pop up and ask them if they are sure they want to do this. If they click the okay button, it should fire off an event and do the necessary database work and reload the page... if not, cancel the postback request and clear the dialog box.
With the code below, I have successuflly hooked into the link button via the targetid property of the ModalPopupExtender so the dialog does popup. However, the okay button does not fire off the event I've written (I've placed a breakpoint in the codebehind within the event, and it does not get touched). Also, the cancel button does not work as it normally would outside of the listview control.
I must be missing something fairly fundamental here, but I'm at a loss - any help would greatly be appreciated. I'm certainly open to alternative methods if this just isn't viable.
<ItemTemplate>
<tr>
<td align="center">
<asp:Label runat="server" ID="lblUserID" Text='<%# Eval("USERID") %>' Visible="false" />
<asp:LinkButton runat="server" ID="lnkRemoveUser" Text="Remove" />
<asp:Panel ID="removeUserModalPanel" runat="server">
<div class="popup">
<div class="loginTitleBar" id="Div1">
Remove User
</div>
<div class="popupBody">
<p>
Are you sure you want to remove this user?
</p>
</div>
<div class="popupControls">
<asp:Button id="btnRemoveUserOkay" runat="server" type="button" Text="Remove User"
onclick="btnRemoveUserOkay_Click" />
<input id="btnRemoveUserCancel" type="button" value="Cancel" />
</div>
</div>
</asp:Panel>
<asp:ModalPopupExtender
ID="removeUserModalPopupExtender"
runat="server"
BackgroundCssClass="ModalPopupBG"
CancelControlID="btnRemoveUserCancel"
TargetControlID="lnkRemoveUser"
PopupControlID="removeUserModalPanel"
drag="false" >
</asp:ModalPopupExtender>
</td>
<td>
<asp:LinkButton ID="lnkUserName" runat="server" Text='<%# Eval("USERNAME") %>' />
</td>
<td>
<asp:Label ID="lblFirstName" runat="server" Text='<%# Eval("FIRSTNAME") %>' />
</td>
<td>
<asp:Label ID="lblLastName" runat="server" Text='<%# Eval("LASTNAME") %>' />
</td>
<td>
<asp:Label ID="lblEmailAddress" runat="server" Text='<%# Eval("EMAILADDRESS") %>' />
</td>
</tr>
</ItemTemplate>
Finally I can make this works. It's a little tricky though. Here are the steps:
Move the panel, the button close and the modalpopupextender outside the listview
Create a HiddenField or whatever control and associate this with the TargetControlID of the ModalPopupExtender control.
In the button on the ListView handle the Click event, and in the code behind call directly to the ModalPopupExtender.Show() method, and voilá.
It is a little dirty indeed, but the ModalPopupExtender seems to override the click event of the listview button when it's associated with the control.
Seems like a problem with having the ModalPopupExtender on a databound repeated row.
Stupid idea #1 : Could you try hiding lnkRemoveUser until the row is selected - then, in the SelectionChanged event, highlight the row, display the button, and hook the button to the ModalPopupExtender?
Stupid idea #2 : Have a hidden button outside the ListView, and hook up your ModalPopupExtender to that. Then have your linkbutton call that button's onclick ().