条件OnClick弹出窗口不会显示为顶部窗口 - 取决于DB& WizardControl文本框值

时间:2015-07-22 14:52:27

标签: javascript c# asp.net messagebox showdialog

Windows 7,C#Web应用程序,VS 2012,.NET 3.5,主要在Google Chrome上进行测试。

我有一个包含几个步骤的向导控件。第一步有一个用户填写的表单,当他们点击" Save&继续>>"(StartNavigationTemplate' s btnNext),我需要检查文本框txtIDno中的内容(如果列出了任何内容。此文本框可以留空,以便为其添加新属性第一次),通过数据库运行此值以确保该数字与我们列出的属性匹配。如果该值有效,则应将用户定向到下一个向导步骤。如果该值无效,则应该有一个模态弹出窗口,通知用户ID No不正确,不应将它们重定向到下一步。

认为这是一项简单的任务,我首先尝试在按钮的点击事件wzDataEntry_ActiveStepChanged中使用MessageBox.Show()。 弹出消息确实出现,但是除非我在调试模式下单步执行代码,否则弹出窗口始终显示在互联网窗口后面(这是在Chrome上测试过的, IE,& Mozilla Firefox)。此允许用户继续编辑表单,尽管它没有正确地重定向到下一步。问题是弹出窗口也没有填充任务栏上的新项目,所以它肯定会被忽视,用户可能想知道为什么他们无法导航到向导的下一步。

.aspx中的向导控制基础:

<div id="wizardContainer" class="wizard-container">
                    <asp:Wizard DisplaySideBar="true" 
                        OnSideBarButtonClick="wzDataEntry_SideBarClick"
                        OnPreviousButtonClick="wzDataEntry_ActiveStepChanged"
                        OnNextButtonClick="wzDataEntry_ActiveStepChanged" 
                        OnFinishButtonClick="wzDataEntry_FinishButtonClick" ID="wzDataEntry" runat="server" Width="100%" ActiveStepIndex="1">
                        <SideBarStyle CssClass="wizard-sidebar" />
                        <SideBarTemplate>
                            <div class="wizard-sidebar-container">
                                <asp:DataList runat="server" ID="SideBarList" RepeatDirection="Horizontal">
                                    <ItemTemplate>
                                    //Stuff
                                    </ItemTemplate>
                                    <SeparatorTemplate>
                                    //Stuff
                                    </SeparatorTemplate>
                                </asp:DataList>
                            </div>
                        </SideBarTemplate>
                        <StartNavigationTemplate>
                            <div class="wizard-navigation">
                                <asp:Button ID="btnNext" runat="server" Text=" Save & Continue >> " CssClass="action-button ds-save-changes"
                                    CommandName="MoveNext" />
                            </div>
                        </StartNavigationTemplate>

                        <StepNavigationTemplate>
                        //stuff
                        </StepNavigationTemplate>

                        <FinishNavigationTemplate>
                        //stuff
                        </FinishNavigationTemplate>

                        <WizardSteps>
                            <asp:WizardStep ID="stepPropertyInfo" Title="Property" AllowReturn="true" StepType="Auto" runat="server">
                                 <div class="clear clearfix top-navigation-buffer"></div>
                                <input type="hidden" id="property-information-step" class="property-information-step" />
                                <div id="Div2" class="data">
                                    <table id="tblPropertyInformationContainer">
                                        <tr>
                                            <td>
                                                <div id="Div3">
                                                    <table id="tblPropertyInformation" class="data-entry-table">
                                                          <tr>
                                                            <td class="label">
                                                                ID#
                                                            </td>
                                                            <td>
                                                                <asp:TextBox ID="txtIDNo" runat="server" CssClass="id-number" MaxLength="10" Width="80" TabIndex="22" ></asp:TextBox>
                                                            </td>
                                                            </tr>
                                                        </table>                                 
                                                  </div>
                                             </td>
                                            </tr>
                                        </table>
                                    </div>
                            </asp:WizardStep>
                           <asp:WizardStep ID="stepOwnerInformation" Title="Seller" AllowReturn="true" StepType="Auto" runat="server">     
                            //Stuff here                      
                            </asp:WizardStep>
                        </WizardSteps>
                    </asp:Wizard>
                </div>

从.aspx.cs点击按钮:

    public void wzDataEntry_ActiveStepChanged(object sender, WizardNavigationEventArgs e)
            {
                int activestep = e.CurrentStepIndex;

                if (activestep == (int)DealInputSteps.PropertyInformation && txtIDno.Text != "" && validateID(txtIDno.Text) == false){
                string message = String.Concat("There was an error saving form because ", txtIDno.Text, " is not a valid ID number. Please confirm the ID number and try again.");

                    //System.Windows.Forms.MessageBox.Show(message); -> I tried this first. This populates item on taskbar but the popup is still hidden behind browser. 
                    //Then I found on SO that TopMost=true should bring this window to the forefront...but it doesn't.
                   //System.Windows.Forms.MessageBox.Show(new System.Windows.Forms.Form { TopLevel = true }, message); -> Same effect as TopMost
                    System.Windows.Forms.MessageBox.Show(new System.Windows.Forms.Form { TopMost = true }, message); //Popup appears behind browser, no item on Windows taskbar, user can still edit form, wizard (properly) does not move on to next step
                    //System.Windows.Forms.MessageBox.Show(message, title, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning, System.Windows.Forms.MessageBoxDefaultButton.Button1, (System.Windows.Forms.MessageBoxOptions)0X40000); -> Throws exception

                    e.Cancel = true;                    
                }
                else
                {
                    UpdateDealStep();
                }
            }

    //I've confirmed that this function is working properly and is not root cause
    protected bool validateID(string IDno)
            {
                string result = "";
                result = //DB is queried here 
                if (result == ""){      
                    return false; 
                }else{
                    return true;
                }

如何确保此弹出窗口显示在浏览器的顶部? 如果此弹出窗口打开时不允许输入,则最好是好。

然后我尝试使用ShowDialog()而不是MessageBox。我尝试添加属性以使弹出窗口显示为所有控件可见,但我没有成功。 此窗口也出现在浏览器后面,允许用户继续编辑表单,但不允许他们导航到下一步。 Windows任务栏上有一个项目可能是对用户的指示,但是控件在左上角被压缩而且无法读取。

public void wzDataEntry_ActiveStepChanged(object sender, WizardNavigationEventArgs e)
        {
            int activestep = e.CurrentStepIndex;

            if (activestep == (int)DealInputSteps.PropertyInformation && txtIDno.Text != "" && validateID(txtIDno.Text) == false){
            string message = String.Concat("There was an error saving form because ", txtMlsNumber.Text, " is not a valid ID number. Please confirm the ID number and try again.");
            string title = "Invalid ID number.";
            System.Windows.Forms.Form popup = new System.Windows.Forms.Form();
            popup.Text = title;
            popup.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            popup.Controls.Add(new System.Windows.Forms.Label() { Text = message, AutoSize = true, TextAlign = System.Drawing.ContentAlignment.MiddleCenter });
            popup.Controls.Add(new System.Windows.Forms.Button() { Text = "OK", DialogResult = System.Windows.Forms.DialogResult.OK, TextAlign = System.Drawing.ContentAlignment.BottomRight });
            popup.ShowDialog();    
                e.Cancel = true;                    
            }
            else
            {
                UpdateDealStep();
            }
        }

ShowDialog()输出:

enter image description here

然后我想我可能会使用javascript&return;确认(); onclientclick()上的方法,但是在访问txtIDno控件时遇到了困难,因为它在向导中,并且在配置条件语句时遇到问题,该条件语句将运行我的服务器端函数来检查数据库。 PageMethods无效,因为我的validateID()函数不能是静态的。我确信我可能错过了关于客户端与服务器端条件函数的更大图片概念,但是如果没有人可以提供我的MessageBox()&amp; /或ShowDialog的解决方案,我可以发布所有失败的尝试。 ()问题。

对于我做错了什么或者最佳做法可能在这里有任何见解????我花了很多时间试图找出这么小的功能而且不知所措。

编辑:

部分解决方案:

我从aspx.cs中找到了一些解决方法,但是有一些不良后果。

  1. 这是迄今为止最好的一个,因为它使弹出窗口显示为顶部窗口。虽然弹出窗口存在但在页面完全加载之前,但是我的页面上的另外两个按钮消失了。一旦用户单击“确定”关闭弹出窗口,它们就会重新出现,但如果没有这样做,则首选它。看起来这只发生在具有服务器端变量(&lt;%=&gt;)的按钮中。 当对话框关闭时,有没有办法让页面无缝回发?
  2.   

    System.Windows.Forms.MessageBox.Show(消息,标题,   System.Windows.Forms.MessageBoxButtons.OK,   System.Windows.Forms.MessageBoxIcon.Warning,   System.Windows.Forms.MessageBoxDefaultButton.Button1,   System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly);

    1. 此方法的行为导致其在Page_Load之前执行,这似乎是在母版页加载之前发生的......当弹出窗口出现时,我的页面上没有背景图像或标题。与上面的解决方案1类似,在用户单击“确定”关闭弹出窗口后,所有内容都会正确加载。 有没有办法在页面开始回发之前或整个页面加载之后调用此javascript函数?
    2.   

      Page.ClientScript.RegisterStartupScript(this.GetType(),&#34; test&#34;,   &#34;提醒(&#39;&#34; +消息+&#34;&#39;)&#34;,true);

      1. 这不是一个漂亮的解决方案,但它比上面两个更有效。这里的问题是,当页面回发时,我的表的CSS消失了。 如何在JS功能回发后使我的页面保留其CSS?

          

        string alert =&#34;&lt;脚本语言=&#39; javascript&#39; &GT;&#34 ;;

             

        提醒+ =&#34;提醒(&#39;&#34; +信息+&#34;&#39;);&#34 ;;

             

        alert + =&#34;&lt; / script&gt;&#34 ;;

             

        回复于(警报);

0 个答案:

没有答案