Javascript 条件OnClick弹出窗口不会显示为顶部窗口-取决于DB&;向导控件文本框值
Windows 7,C#Web应用程序,VS 2012,.NET 3.5,主要在Google Chrome上测试 我有一个包含几个步骤的向导控件。第一步是用户填写一个表单,当他们单击“Save&Continue>>”(StartNavigationTemplate的btnNext)时,我需要检查文本框txtIDno中的内容(如果列出了任何内容。对于首次添加的新属性,此文本框可能为空),在数据库中运行此值,以确保数字与我们列出的属性匹配。如果该值有效,则应将用户引导到下一个向导步骤。如果该值无效,则应出现一个模式弹出窗口,通知用户ID号不正确,并且不应将其重定向到下一步 考虑到这将是一项简单的任务,我首先尝试在按钮的click事件wzDataEntry_ActiveStepChanged中使用MessageBox.Show()。弹出消息确实会在应该的时候出现,但是除非我在调试模式下单步执行代码,否则弹出消息总是出现在internet窗口后面(这是在Chrome、IE和Mozilla Firefox上测试的)。这允许用户继续编辑表单,尽管它不会正确地重定向到下一步。问题是弹出窗口也不会填充任务栏上的新项目,因此它肯定会被忽略,用户可能会想知道为什么他们无法导航到向导的下一步 .aspx中的向导控件基础:Javascript 条件OnClick弹出窗口不会显示为顶部窗口-取决于DB&;向导控件文本框值,javascript,c#,asp.net,messagebox,showdialog,Javascript,C#,Asp.net,Messagebox,Showdialog,Windows 7,C#Web应用程序,VS 2012,.NET 3.5,主要在Google Chrome上测试 我有一个包含几个步骤的向导控件。第一步是用户填写一个表单,当他们单击“Save&Continue>>”(StartNavigationTemplate的btnNext)时,我需要检查文本框txtIDno中的内容(如果列出了任何内容。对于首次添加的新属性,此文本框可能为空),在数据库中运行此值,以确保数字与我们列出的属性匹配。如果该值有效,则应将用户引导到下一个向导步骤。如果该值无效,
<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>
如何确保此弹出窗口显示在浏览器顶部?如果此弹出窗口打开时不允许输入,则更好
然后我尝试使用ShowDialog()而不是MessageBox。我已经尝试添加属性,以使弹出窗口显示在所有控件可见的中心,但我没有成功。此窗口也显示在浏览器后面,允许用户继续编辑表单,但不允许他们导航到下一步。windows任务栏上有一个项目可能是用户的指示,但是控件在左上角被压扁,不可读
ShowDialog()输出:
然后我想我可以使用javascript的return confirm();方法,但在访问txtIDno控件时遇到了困难,因为该控件位于向导中,并且在生成将运行服务器端函数检查数据库的条件语句时遇到了问题。PageMethods将无法工作,因为我的validateID()函数不能是静态的。我确信我可能缺少一个关于客户端与服务器端条件函数的更大概念,但如果没有人能为我的MessageBox()和/或ShowDialog()问题提供解决方案,我可以发布我在这方面的所有失败尝试
任何关于我做错了什么或最佳实践是什么的见解????我花了很长时间试图弄明白这样一个小功能,但我不知所措
编辑:
部分解决方案:
我从我的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;
}
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();
}
}