2011-02-28 100 views
4

可能重複:
Button OnClick not firing on first click in ASP.NET?按鈕OnClick沒有在第一次點擊ASP.NET發射?

<asp:Button ID="buttonSub" runat="server" CssClass="btn9" 
      OnClick="buttonSub_Click" OnClientClick="return confirmation();" Text="Next" /> 
     <asp:Button ID="ButtonCancel" runat="server" 
      CssClass="btn9" OnClick="ButtonCancel_Click" CausesValidation="false" Text="Cancel" /> 


try 
    { 

     //Resize the Photo Image 

     ResizePhoto(); 

     //Resize the Company Logo Image 
     ResizeCompanyLogo(); 

     bool ErrorGuid = false; 

     string LoginNameChecking = "<MortValidLoanOfficerLoginName><LoginName>" + textboxLoginName.Text.Trim() + "</LoginName></MortValidLoanOfficerLoginName>"; 

     dsLogincheck = objGeneric.GenericMethod(LoginNameChecking, "MortValidLoanOfficerLoginName", out ErrorGuid); 

     if (Convert.ToInt32(dsLogincheck.Tables[0].Rows[0][0]) == 1) 
     { 

      Session["firstname"] = textboxFirstName.Text; 

      Session["lastname"] = textboxLastName.Text; 

      Session["loginpassword"] = textboxLoginPassword.Text.Trim(); 
      Session["reenterpassword"] = textboxReEnterPassword.Text.Trim(); 
      Session["emailaddress"] = textboxEmailAddress.Text.Trim(); 

      Session["loanofficertype"] = DropDownListLoanOfficerType.SelectedItem.Value.Trim(); 
      Session["companyname"] = textboxCompanyName.Text.Trim(); 
      Session["companyurl"] = textboxCompanyURL.Text.Trim(); 
      Session["registrationperiod"] = DropDownListRegistrationPeriod.SelectedItem.Value.Trim(); 
      Session["RegistrationAmount"] = Convert.ToString(100 * int.Parse(DropDownListRegistrationPeriod.SelectedItem.Value)); 
      Session["str"] = "yes"; 


      textboxLoginName.Text = ""; 
      ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "<script>alert('login name already exists Please enter another login name');</script>", false); 
      Response.Redirect("~/LoanOfficerRegistration.aspx"); 
     } 
     else 
     { 
      Server.Transfer("CreditCardInfo.aspx", true); 

     } 
    } 
    catch (Exception ExeptionMessage) 
    { 


    } 


protected void ButtonCancel_Click(object sender, EventArgs e) 
{ 

    Session["LoginValidation"] = null; 
    Response.Redirect("~/Logon.aspx"); 
} 

這是一個好註冊。取消按鈕無法正常工作首先點擊當sumbmit按鈕點擊一次,然後點擊取消按鈕點擊兩次其工作的智慧它不工作。 PLZ給這個問題的解決方案。

保護無效的Page_Load(對象發件人,EventArgs的){

if (!IsPostBack) 
    { 
     GetLoanOfficerid(); 
     textboxFirstName.Focus(); 
     //Values Assigning to Registration Page Controls if Login Name Already Exists 
     if (Session["str"] == "yes") 
     { 
      Page.RegisterStartupScript("aa", "<script>alert('login name already exists Please enter another login name');</script>"); 


      textboxFirstName.Text = (String)Session["firstname"]; ; 
      textboxLastName.Text = (String)Session["lastname"]; 
      textboxLoginName.Text = ""; 
      textboxLoginName.Focus(); 
      textboxLoginPassword.Text = (String)Session["loginpassword"]; 

      textboxReEnterPassword.Text = (String)Session["reenterpassword"]; 
      textboxEmailAddress.Text = (String)Session["emailaddress"]; 


      DropDownListLoanOfficerType.Text = (String)Session["loanofficertype"]; 
      textboxCompanyName.Text = (String)Session["companyname"]; 
      textboxCompanyURL.Text = (String)Session["companyurl"]; 
      DropDownListRegistrationPeriod.Text = (String)Session["registrationperiod"]; 
      textboxRegistrationAmount.Text = (String)Session["RegistrationAmount"]; 
     } 
     //Values Assigning to Registration Page Controls When Back Button is Click in CreditCardinfo Page 
     if (Session["page"] == "yes") 
     { 
      textboxFirstName.Text = (String)Session["firstname"]; ; 
      textboxLastName.Text = (String)Session["lastname"]; 
      textboxLoginName.Text = (String)Session["loginname"]; 
      //textboxLoginName.Focus(); 
      textboxLoginPassword.Text = (String)Session["loginpassword"]; 

      textboxReEnterPassword.Text = (String)Session["reenterpassword"]; 
      textboxEmailAddress.Text = (String)Session["emailaddress"]; 


      DropDownListLoanOfficerType.Text = (String)Session["loanofficertype"]; 
      textboxCompanyName.Text = (String)Session["companyname"]; 
      textboxCompanyURL.Text = (String)Session["companyurl"]; 
      DropDownListRegistrationPeriod.Text = (String)Session["registrationperiod"]; 
      textboxRegistrationAmount.Text = (String)Session["RegistrationAmount"]; 

     } 

    } 
} 
+2

同樣的問題可能複製http://stackoverflow.com/questions/5138129/button-onclick-not-firing-on-first-click-in-asp -net – 2011-02-28 04:54:48

+2

不會發布與第一個問題完全相同的第二個問題,請編輯您的原始問題幷包含其他信息。這個問題應該關閉或合併。 – 2011-02-28 04:58:15

+0

客戶端確認()函數是什麼樣的? – DaveB 2011-02-28 05:56:56

回答

0

確保您捕捉的IsPostBack在Page_Load功能。

如果(this.IsPostBack) {}

+0

if(!IsPostBack)已經寫了這段代碼但不能正常工作 – rams 2011-02-28 04:57:49

+0

請問您可以發佈你的PageLoad函數嗎? – 2011-02-28 04:59:08

+0

已經發送上面plz查找 – rams 2011-02-28 06:01:47

相關問題