简体   繁体   English

ASp.net按钮jqueryui Dialog导致所有数据重置。 UsesubmitBehavior = False,并且数据绑定在(!ispostback)中

[英]ASp.net Button on jqueryui Dialog causes all from data to reset. UsesubmitBehavior=False, and databind in (!ispostback)

So I've been struggling with this for a couple days now. 所以我现在已经苦苦挣扎了好几天了。 I have a login page, that checks if the user is logging in for the first time, and if so, it shows a jqueryui Dialog box asking the user to pick their security questions. 我有一个登录页面,用于检查用户是否第一次登录,如果是,则显示一个jqueryui对话框,要求用户选择他们的安全问题。 The Dialog is simple, three dropdowns, three text boxes, and a continue and cancel button. 对话框很简单,有三个下拉菜单,三个文本框以及一个继续和取消按钮。 The dialog is displaying find, and when you click continue, the data is saved to the database, but it only saves the default values of the dropdownlists, and it doesnt save the text from the text boxes. 该对话框显示find,当您单击continue时,数据将保存到数据库中,但它只保存下拉列表的默认值,并且不会保存文本框中的文本。 It seems to me like the form is posting back before the data saves, and then saves the blank/default content. 在我看来,表单在数据保存之前回发,然后保存空白/默认内容。 I've tried everything I can find on the internet to fix this. 我已经尝试了我可以在互联网上找到的一切来解决这个问题。 As of right now, I'm launching the dialog box on page load for testing purposes. 截至目前,我正在启动页面加载对话框以进行测试。 Code Below: 代码如下:

Javascript: 使用Javascript:

function validateQuestions() {

            var q1Index = $('#<%= ddlQuest1.ClientID%>').get(0).selectedIndex;
            var q2Index = $('#<%= ddlQuest2.ClientID%>').get(0).selectedIndex;
            var q3Index = $('#<%= ddlQuest3.ClientID%>').get(0).selectedIndex;
            "<%=Q3Index%>" = q3Index;
            var label = document.getElementById('<%= _lblQuestError.ClientID%>');
            label.style.display = 'none';

            if (q1Index == q2Index || q1Index == q3Index || q2Index == q3Index) {label.style.display = 'block';}
            else {label.style.display = 'none'}
            return false;
        }

        function validateAnswers() {

            var ans1Text = $('#<%= txtAnswer1.ClientID%>').val();
            var ans2Text = $('#<%= txtAnswer2.ClientID%>').val();
            var ans3Text = $('#<%= txtAnswer3.ClientID%>').val();
            var ans1error = document.getElementById('<%= _lblAns1Error.ClientID%>');
            var ans2error = document.getElementById('<%= _lblAns2Error.ClientID%>');
            var ans3error = document.getElementById('<%= _lblAns3Error.ClientID%>');
            ans1error.style.display = 'none';
            ans2error.style.display = 'none';
            ans3error.style.display = 'none';

            if(ans1Text=""){ans1error.style.display = 'block';}                
            else if(ans2Text=""){ans2error.style.display = 'block';}
            else if(ans3Text=""){ans3error.style.display = 'block';}
            else { ans1error.style.display = 'none'; ans2error.style.display = 'none'; ans3error.style.display = 'none'}

            return false;
        }
function cancel() {
            $("#_dlgQuest").dialog('close');
            return false;
        }
function showDialog() {
            var secQuestDlg = $('#_dlgQuest').dialog({
                bgiframe: true,
                height: 350,
                width: 900,
                modal: true,
                overlay: {
                    backgroundColor: '#000',
                    opacity: ".8"
                }
            });
            secQuestDlg.parent().appendTo('/html/body/form[0]');
        }

Button aspx: <asp:Button ID="_dlgbtnContinue" ToolTip="Continue" runat="server" Text="Continue" UseSubmitBehavior="false" OnClick="_dlgbtnContinue_Click" CausesValidation="false" /> 按钮aspx: <asp:Button ID="_dlgbtnContinue" ToolTip="Continue" runat="server" Text="Continue" UseSubmitBehavior="false" OnClick="_dlgbtnContinue_Click" CausesValidation="false" />

PageLoad: pageLoad的:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlQuest3.Attributes.Add("onchange", "javascript:validateQuestions();");
            ddlQuest1.Attributes.Add("onchange", "javascript:validateQuestions();");
            ddlQuest2.Attributes.Add("onchange", "javascript:validateQuestions();");
            txtAnswer1.Attributes.Add("onblur", "javascript:validateAnswers();");
            txtAnswer2.Attributes.Add("onblur", "javascript:validateAnswers();");
            txtAnswer3.Attributes.Add("onblur", "javascript:validateAnswers();");  
            List<String> lstQuestions = QuikDrawServiceHelper._QuikDrawClient.GetQuestions();               
            ddlCountry.Focus();
            FillQuestions();
            ClientScript.RegisterStartupScript(GetType(), "hwa", "showDialog()", true);
            }
    }

Fillquestions: Fillquestions:

try
            {
                foreach (string s in lstQuestions)
                {
                    if (s.Equals(Customer.Quest1Code))
                    {
                        q1 = s;
                    }
                    if (s.Equals(Customer.Quest2Code))
                    {
                        q2 = s;
                    }
                    if (s.Equals(Customer.Quest3Code))
                    {
                        q3 = s;
                    }
                }
            }
            catch (Exception ex)
            {

            }

Complete Click Event: 完成点击事件:

protected void _dlgbtnContinue_Click(object sender, EventArgs e)
        {  
            Customer = CompanyServiceHelper._CompanyClient.GetCustomerByID(Convert.ToInt32(Session["CustomerID"].ToString()));   
            if (Session["FirstLogin"] == "Yes")
            {
                Customer.Quest1Code = ddlQuest1.SelectedValue;
                Customer.Quest1Ans = txtAnswer1.Text;
                Customer.Quest2Code = ddlQuest2.SelectedValue;
                Customer.Quest2Ans = txtAnswer2.Text;
                Customer.Quest3Code = ddlQuest3.SelectedValue;
                Customer.Quest3Ans = txtAnswer3.Text;
                CompanyServiceHelper._CompanyClient.AddQuestionsForCustomer(Customer);
                Session["FirstLogin"] = "Yes";
                Session["CustID"] = Customer.CustID;                
    }

I've tried linkbuttons as well, and i get the same thing. 我也试过了链接按钮,我也得到了相同的东西。 Any help would be greatly appreciated. 任何帮助将不胜感激。

The root cause of the problem you are facing is the fact that the dialog is made "display:none" when popup disappears, and this resets all the values inside the dialog, making them not accessible on server. 您遇到的问题的根本原因是,当弹出窗口消失时,对话框将显示为“display:none”,这会重置对话框中的所有值,使其无法在服务器上访问。 Despite "runat=server", form fields are not accessible on server bcz of "display:none", making you think the values are never set !! 尽管“runat = server”,表单字段在“display:none”的服务器bcz上无法访问,让您认为值永远不会被设置!!

Seems like when you click the dlgbtnContinue button it is still not doing a postback, therefore you get the !isPostBack all over, and then resets the values. 好像当你单击dlgbtnContinue按钮时它仍然没有进行回发,因此你得到了!isPostBack ,然后重置值。 After this, the _dlgbtnContinue_Click event is getting triggered, saving the blank values. 在此之后, _dlgbtnContinue_Click事件将被触发,保存空白值。 Maybe try to check in !isPostBack if also the values in the DropDown are not the default, meaning that if they are not the default values you do not want to get inside that if again. 也许尝试检入!isPostBack如果DropDown中的值也不是默认值,这意味着如果它们不是默认值,您不希望再次进入。 Just an idea... It would be good to have the _dlgbtnContinue_Click code. 只是一个想法......拥有_dlgbtnContinue_Click代码会很好。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM