c# - 在 ASP.NET 中第一次单击时按钮 OnClick 没有触发?

标签 c# asp.net

<分区>

Possible Duplicate:
Button OnClick not firing on first click in 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");
}

这是一张注册表。取消按钮不起作用首先单击当提交按钮单击一次然后单击取消按钮单击两次它的工作否则它不起作用。 请给出这个问题的解决方案。

protected void Page_Load(object sender, EventArgs e) {

    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"];

        }

    }
}

最佳答案

确保在 Page_Load 函数中捕获 IsPostBack。

如果(这个.IsPostBack) {

关于c# - 在 ASP.NET 中第一次单击时按钮 OnClick 没有触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5138300/

相关文章:

有关在粒度级别上处理文件的 C# 入门知识或示例

c# - C#中继承的性能考虑

c# - ScriptManager.RegisterClientScriptIninclude 之后的 Javascript 对象 "is not defined"错误

asp.net - ELMAH 登录 SQL Server

ASP.NET 图表控件无法在生产服务器上运行

C# ASP.NET、WebForms 到 MVC : Does it make sense to change in our case?

c# - 从 GAC 动态加载最新的程序集版本

c# - WPF 绑定(bind)与事件处理

c# - 如何在后面的代码中使文本框只读属性为 false?

asp.net - Web 浏览器进入信息亭模式