在Asp.Net中多次单击按钮时避免页面刷新事件

时间:2018-05-27 09:12:08

标签: c# asp.net

我有一个页面,我有一个“添加更多”按钮。每当我点击这个按钮时,我的“rowNum”增加1并完成工作。现在,它在没有单击页面刷新按钮的情况下工作正常。但是,每当我单击页面刷新时,再次执行“添加更多”执行的上一个操作。我已经看到了各种可能的解决方案,以避免在oline平台中刷新页面,但是解决方案就像是当他们检测到它是页面刷新时他们在提交表单的情况下避免它但在我的情况下我不能这样做,因为我即使用户单击中间的刷新按钮,也必须反复单击“添加更多”按钮。我已经尝试了几天可行的解决方案,请帮助我。我正在附上我的代码:

    static int rowNum;
        string applicantUserid = "";
        EmployeeHistDS employeeHistDS = new EmployeeHistDS();
        EmployeeHistDS universityDS = new EmployeeHistDS();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                loadCompanyInfo();
                if (!IsPostBack)
                {
                    rowNum = 1;
                    if (this.Context.User.Identity.Name != "")
                    {
                        hdnApplicantUserID.Value = this.Context.User.Identity.Name;
                        loadCombo();
                        divMessageFailed.Visible = false;
                        divMessageSuccess.Visible = false;
                        RecruitmentDS eduDS = UtilUI.GetApplicantEducationList(Convert.ToInt32(hdnApplicantUserID.Value));
                        if (eduDS != null && eduDS.Job_Applicant_EduInfo.Rows.Count > 0) loadUserCombo(eduDS);

                        JobDetailsDS jobsDS = new JobDetailsDS();
                        if (this.Context.User.Identity.Name != "") jobsDS = UtilUI.GetApplicantBasicInformation(this.Context.User.Identity.Name);
                        if (jobsDS != null && jobsDS.Job_Application.Rows.Count > 0 && !jobsDS.Job_Application[0].IsAPPLICANTNAMENull()) loginUserName.Text = "Welcome, <span class='bold' style='color:orange'>" + jobsDS.Job_Application[0].APPLICANTNAME + "</span>";
                        loginUserName.Visible = true;
                        login.Visible = false;
                    }
                    else if (Request.QueryString["id"] != null && UtilUI.Decrypt(Request.QueryString["id"].ToString()) != "")
                    {
                        hdnApplicantUserID.Value = UtilUI.Decrypt(Request.QueryString["id"].ToString());
                        loadCombo();
                        divMessageFailed.Visible = false;
                        divMessageSuccess.Visible = false;
                        logout.Visible = false;
                    }
                    else
                    {
                        loadCombo();
                        divMessageFailed.Visible = true;
                        lblError.ForeColor = Color.Red;
                        lblError.Text = "Please Fill Up Personal Information First to Add Education.";
                        divMessageSuccess.Visible = false;
                        logout.Visible = false;
                    }
                }
                else
                {
                    employeeHistDS = UtilUI.getDegreeList();
                    universityDS = UtilUI.getUniversityList();
                    _clearValidationMsg();
                    if (hdnApplicantUserID.Value == "")
                    {
                        divMessageFailed.Visible = true;
                        lblError.ForeColor = Color.Red;
                        lblError.Text = "Please Fill Up Personal Information First to Add Education.";
                        divMessageSuccess.Visible = false;
                    }
                    else
                    {
                        divMessageFailed.Visible = false;
                        divMessageSuccess.Visible = false;
                    }
                }
                MenuItemUrl();
            }
            catch { }

        }
protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (rowNum != 8)
            {
                rowNum++;
                if (rowNum == 2) addNewRow2();
                else if (rowNum == 3) addNewRow3();
                else if (rowNum == 4) addNewRow4();
                else if (rowNum == 5) addNewRow5();
                else if (rowNum == 6) addNewRow6();
                else if (rowNum == 7) addNewRow7();
                else if (rowNum == 8) addNewRow8();
            }
            else
            {
                lblError.Text = "You Can Add Max 5 Post Graduation Information.";
                lblError.ForeColor = Color.Red;
                divMessageFailed.Visible = true;
                divMessageSuccess.Visible = false;
            }
        }

我附上了一张图片,以便您更好地理解:   this is the case scenerio 谢谢。

0 个答案:

没有答案