Button does not fire first click but it fires well second click

Hi All,

I developed a web form that have one button named saveButton. When run project then click button it does not work just refresh page after than i clicked again click event worked fine. Anybody know what i missing.  

 Thanks

My Sample code :

protected void saveButton_Click(object sender, EventArgs e)

{

Response.Redirect(
"ListPage.aspx?lpt=" + (int)ObjectTypes.VehicleCounterValue, true);

}

 

0
hasanozel
4/6/2009 11:48:13 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

10 Replies
2564 Views

Similar Articles

[PageSpeed] 46
Get it on Google Play
Get it on Apple App Store

Can you place your aspx page code so that I can better help you...

Thanks,

Khushboo Nayak

-1
khushi_nayak
4/6/2009 1:21:49 PM

Should work, can you paste the code of aspx page

0
dreamitaspdotnet
4/6/2009 1:31:28 PM

 Yes, should work. or you tried to click the button twice before it completed postback loading. Check again or post code.

-1
msramachandran
4/6/2009 1:40:39 PM

Hi,

My code is here ,

 

Thanks for all your help.

Hasan ÖZEL 

<%@ Page Language="C#" MasterPageFile="~/mainPage.master" AutoEventWireup="true" CodeBehind="EditVehicleCounterValue.aspx.cs" Inherits="BL.AracKilometreTakip.Web.EditVehicleCounterValue" Title="Kullanıcı Giriş/Güncelleme Sayfası" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <table cellpadding="0" cellspacing="10" border="0" width="100%">
        <tr>
            <td class="Title1" colspan="2">
                <asp:Label ID="titleLabel" runat="server" CssClass="Title1"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="FieldName" width="10%">&nbsp;Araç</td>
            <td>
                <asp:DropDownList ID="vehicleDropDownList" runat="server" CssClass="ComboTextBox"
                    Width="250px" AutoPostBack="True" OnSelectedIndexChanged="vehicleDropDownList_SelectedIndexChanged">
                </asp:DropDownList>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="vehicleDropDownList"
                    CssClass="Error" Display="Dynamic" ErrorMessage="Lütfen Araç bilgisi için geçerli bir değer seçiniz."
                    InitialValue="0">*</asp:RequiredFieldValidator>
               
           </td>
        </tr>
        <tr>
            <td class="FieldName" width="10%">&nbsp;Yıl</td>
            <td>
                <asp:DropDownList ID="yearDropDownList" runat="server" CssClass="ComboTextBox"
                    Width="125px">
                </asp:DropDownList>
           </td>
         <tr>  
            <td class="FieldName" width="10%">&nbsp;Ay</td>
            <td>
                <asp:DropDownList ID="monthDropDownList" runat="server" CssClass="ComboTextBox"
                    Width="125px">
                </asp:DropDownList>
           </td>      </tr>
        <tr>
            <td class="FieldName" width="10%">
                Sayaç Okuma</td>
            <td>
                <asp:TextBox ID="counterValueTextBox" runat="server" CssClass="ComboTextBox" Width="250px" AutoPostBack="True" ></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="counterValueTextBox"
                    CssClass="Error" Display="Dynamic" ErrorMessage="Lütfen Sayaç Okuma bilgisi için geçerli bir değer giriniz.">*</asp:RequiredFieldValidator>&nbsp;
                <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="counterValueTextBox"
                                CssClass="Error" ErrorMessage="Sayaç Okuma Bilgisi İçin Geçerli Bir Değer Giriniz"
                                Operator="DataTypeCheck" Type="Integer">*</asp:CompareValidator>            
               </td>
        </tr>
        <tr>
            <td colspan="2">
                <table cellspacing="2" cellpadding="0" border="0" width="100%">
                    <tr>
                        <td width="1%"><input type="button" class="Button1" onclick="javascript:history.go(-1);" value=" < Geri"/></td>
                        <td width="99%"><asp:Button ID="saveButton" runat="server" Text="Kaydet" CssClass="Button1" OnClick="saveButton_Click"/></td>
                    </tr>
                </table>
               
             </td>
        </tr>
        <tr>
            <td colspan="2"  height="88%" width="50%" valign="top">
                <asp:Label ID="errorLabel" runat="server" Text="Seçilen araca ait önceden girilmiş bir sayaç bilgisi bulunmamaktadır." CssClass="Error"></asp:Label>
                <div style="height:98%;overflow:auto;width:50%">
                    <asp:GridView id="listGridView" runat="server" AutoGenerateColumns="False" ShowFooter="false"  Width="100%">
                        <PagerStyle CssClass="gridPagerStyle" HorizontalAlign="Center"  />
                        <SelectedRowStyle CssClass="gridSelectedItemStyle" />
                        <HeaderStyle CssClass="gridHeaderStyle" />
                        <AlternatingRowStyle CssClass="gridAlternatingItemStyle"  />
                        <RowStyle CssClass ="gridItemStyle" />
                        <Columns>
                            <asp:BoundField DataField="Year" HeaderText="Yıl">
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Month" HeaderText="Ay" >
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="CounterValue" HeaderText="Sayaç Okuma"  >
                                <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                        </Columns>
                    </asp:GridView>
                </div>
            </td>
        </tr>
       
    </table>
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
        ShowSummary="False" />
 </ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

0
hasanozel
4/6/2009 1:41:55 PM

Button is working for me on the first click, try in different browsers firefox or opera

-1
dreamitaspdotnet
4/6/2009 1:45:05 PM

Hi dreamitaspdotnet,

i tried in different browser firefox. It is completely the same result with İE. It is not worked with  firefox. I think it is not browser problem. I thing i missed someting easier.

Thanks for all your help

Hasan 

 

 

-1
hasanozel
4/6/2009 1:56:51 PM

This issue occurs whenever you are using update panel and the triggers for the update panel are not set properly.

(Some times this is because of one update panel inside another update panel.)

0
mcr_subbu
4/6/2009 2:06:47 PM

Hi,

 I checked that i have only one updatepanel in my webform and i did not use any trigger for update panel.  I recreate the update panel but my problem still continues.

 

0
hasanozel
4/6/2009 2:34:10 PM

Remove the update panel completely and check it once.

0
mcr_subbu
4/6/2009 2:59:33 PM

Hi,

I finally found the mistake. One of textbox object's autopastback property value is true. I set autopostback value to false. Now it works fine. 

 Thanks for all you help.

Hasan

0
hasanozel
4/7/2009 5:50:11 AM
Reply:

Similar Artilces:

Event not Firing on first click, but fires on second click
 Hey Guys,I am working on a page where I am synamicall creating controls, and then adding events to those controls.Those events are not firing on the first click, but they are firing on th second click.  using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using com.chrome.kp.configcompare3;using System.Drawing; public partial class new_build...

Button Click Not Firing On First Click
I have a web form that uses a Save button (see below) to save data.  When I open the page and enter data and click on the Save button the page refreshes (as in a post back) but it doesn't save the changes.  I don't get any error messages either.  If I click it a second time it saves the data.  I've tried all methods of debugging I can think of, but I can't find the problem.  The click event doesn't appear to fire the first time, but it does fire the second time.  Any idea what the problem is? <asp:linkbutton id="SaveButton"...

Button click event not firing on the first click
I have three buttons on my form but when I click on the button, it does not fire the button click event. I looked at the call stack. However when I click on the second time it does. I have three buttons and they all act the same way. Here is a sample of my code private void btnSubmit_Click(object sender, System.EventArgs e) { this.dgResults.CurrentPageIndex = 0; FillGrid(); } private void btnExport_Click(object sender, System.EventArgs e) { this.dgResults.CurrentPageIndex = 0; this.dgResults.AlternatingItemStyle.BackColor =System.Drawing.Color.White; this.dgResults.AllowPaging =...

Button click inside an updatepanel fires only on second click
Hello,  I have an update panel with a listbox, two textboxes and a button. The following code should fire when the user clicks the button: 1    Protected Sub SavePriorityButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)2            Dim PTSCon As New SqlConnection(ConfigurationManager.ConnectionStrings("TaskTrackerConnectionString").ConnectionString)3            Dim PriorityName As New SqlParameter("@PriorityName", Data.SqlDbType.VarChar)4   ...

Image button .click event not firing the first time clicked
I have an image button that saves a record to my backend. It has the CausesValidaton property = "True". The first time, the button is clicked, it causes a postback, but the image buttons .click event is not fired. For each subsequent click, the postback gets called, then the image buttons .click event is fired as expected. I have done this simple task numerous times, so I'm a little stumped. I've troubleshot everything I can think of (including cross referencing all the properties of both the page and control against working production examples). Here's the handler for my button. Thanks fo...

button click event from another button click not firing
 Hi,  I want to trigger a button click event from another button click .It is not firing.  Please help.  protected void btnReview_Click(object sender, EventArgs e) {       if (MandatoryValidation())        {         this.Button1.Click += new System.EventHandler(this.Button1_Click);       } }protected void Button1_Click(object sender, EventArgs e) { } protected void btnReview_Click(object sender, EventArgs e){   &...

On click event firing on second click
Hi All,  I have made a custom control for changing the index on a paged datalist that I have created. I have made a control because i want to use it in multiple places. The built in gridview, details view ect were not up to the task, although at least there paging worked.  The problem is that I dynamicaly create the linkbuttons and add them to a place holder. As i create the linkbutton I wire up its click event like so: LB.Click += new EventHandler(LB_Click); This works on the first click and the control consumes the event and re-loads the list from the correct index and re-cre...

Button click event fired only on clicking twice
Hi, My application is developed using VS 2005 - Web Application. In one of the pages, I added a button and a click event for the same. On clicking the button I perform some operation. But only if i click the button twice, the click event is fired. I tried every thing from rebuilding the solution to adding the button controls dynamically but of no avail. Any pointers? Thanks, Sandhya Hello Sandhya, Would you please post the entire page including the .aspx and .aspx.cs/vb? It would be helpful to track down the problem. Thank you, JessicaJessica CaoSincerely,Microsoft Online Communit...

Click Event not firing when submit button is clicked
I have a form with several textboxes, one dropdown list, and a checkbox.  If I type something into a textbox and click on the submit button, the click event for the submit button does not fire, though the form does postback.  If I click on it again, it will fire the click event.  On the other hand, if I click on the checkbox, or dropdownlist, rather than typing into the textbox, then click on submit, it fires as expected.  Does anyone have an explanation and solution?  Thanks in advance for any help! Elliott post your code - sounds like postback...

the button works after second click but not at the first click !
hello dear friends i have a page. it contains a button , and in the click event of that, there is a piece of vb code .after running the application, there is a problem. the problem is :at the first time when i want to click the button,nothing happen ( i mean the codes don't written in click button, don't affect. )but in the second time, after the first time, the codes run , and i can see the affected codes.what can i do to solve this problem? an example code : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.Attributes.Add...

Button not firing on first click
Hi I have a  button which on the first click it should bring up a popup, however its not working until i click it again. My code is below, what am i doing wrong, thank you. My html code is here;<ItemTemplate> <asp:Button type="button" id=btnModify runat="server" Text="Modify" cssclass="button"></asp:Button></ItemTemplate> </asp:TemplateColumn>   And my code behind is here; System.Web.UI.WebControls.Button btnModify = (System.Web.UI.WebControls.Button)e.Item.FindControl("btnModify"); btnMod...

An OnClick event doesn't fire up when a button is clicked in a Tab Panel in a Tab Container in an AJAX Web Form
Hello Post: I would like to enclose the following code so you can analize what is going on: "> " style="vertical-align:top;"> "> "> ...

How to fire the button click event in web part?
If I created a button control programmatically in a web form, I would use   public Button btnSearch = new Button();protected override void CreateChildControls(){ Button1.Click += new System.EventHandler(this.Button1_Click); this.Controls.Add(Button1); } protected void Button1_Click(object sender, EventArgs e) { //code here. }It doesn't work in a web part. It bombed at this.Controls.Add(Button1); after I clicked the button. How does the button click event get fire in web part? Thanks.DY  Im a bit confused here.. can you elaborate more? What really is your re...

UPDATE BUTTON EVENT WAS NOT WORKING AT FIRST CLICK AFTER SECOND CLICK ONLY ITS WORKING
Hi,    I am working in asp.net With ajax extension. In a form have a update button,on the first click,event not calling,on the second click its calling that event successfully. Give a solution for this problem. Thanks in Advance Are you using updatepanels? There might be a problem with the lifecycle of your page. Can you show some code?Jef Claes~~~~~~~~~~Visit my blog S ur thought is right i am using update panel.My Code is below    </script> <br /> <br /> <asp:Label ID="Label1" runat="server" CssClass="header...