javascript - Conditional OnClick popup will not appear as top window - Dependent on DB & WizardControl textbox value -
windows 7, c# web application, vs 2012, .net 3.5, testing on google chrome.
i have wizard control several steps. first step has form user fills out , when click "save & continue >>"(startnavigationtemplate's btnnext), need check what's in textbox txtidno(if listed. textbox may left empty new properties being added first time), run value through database ensure number matches property have listed. if value valid, user should directed next wizard step. if value not valid, there should modal pop-up window informing user id no incorrect, , should not redirected next step.
thinking easy task, first tried using messagebox.show() in button's click event, wzdataentry_activestepchanged. the popup message appear when should, unless stepping through code in debug mode, popup appears behind internet window (this tested on chrome, ie, & mozilla firefox). allows user continue edit form, although not redirect next step. problem popup doesn't populate new item on taskbar either, surely go unnoticed , user may wonder why cannot navigate next step of wizard.
wizard control basics .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>
button click .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 error saving form because ", txtidno.text, " not valid id number. please confirm id number , try again."); //system.windows.forms.messagebox.show(message); -> tried first. populates item on taskbar popup still hidden behind browser. //then found on topmost=true should bring window forefront...but doesn't. //system.windows.forms.messagebox.show(new system.windows.forms.form { toplevel = true }, message); -> same effect 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) not move on 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 function working , not root cause protected bool validateid(string idno) { string result = ""; result = //db queried here if (result == ""){ return false; }else{ return true; }
how can ensure popup appear on top of browser??? preferable if not allow input while popup open, well.
i tried using showdialog() instead of messagebox. i've tried adding attributes popup appear centered controls visible, have not been successful. this window appears behind browser , allows user continue editing form, although not allowing them navigate next step. there item on windows taskbar may indication user, controls squished in top left-hand corner , not readable.
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 error saving form because ", txtmlsnumber.text, " not valid id number. please confirm id number , 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() output:
i thought might use javascript's return confirm(); method on onclientclick() have struggled accessing txtidno control because in wizard , had trouble formulating conditional statement run server-side function check database. pagemethods not work because validateid() function cannot static. sure missing bigger picture concept in regards client vs server-side conditional functions, can post failed attempts @ if no 1 can offer solution messagebox() &/or showdialog() issues.
any insight doing wrong or best practice might here???? i've spent ridiculous amount of time trying figure out such small piece of functionality , @ loss.
edit:
partial solutions:
i have found workarounds aspx.cs, there undesired consequential effects.
- this best 1 far, makes popup appear top window. while popup present , before page loads, however, 2 other buttons on page disappear. reappear user clicks ok close popup, it'd preferred if did not occur. appears occurring buttons have server-side variable (<%= >) in them. is there way make page seamlessly postback @ once when dialog box closed?
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.defaultdesktoponly);
- this method's behavior causes execution right before page_load, seems occurring before master page loads... while popup present, there no background image or header on page. solution 1 above, load after user clicks ok close popup. is there way call javascript function either before page starts postback or after whole page has loaded?
page.clientscript.registerstartupscript(this.gettype(), "test", "alert('" + message + "')", true);
this not pretty solution, works more seamlessly 2 above. problem here when page posts back, css table gone. how can make page retain css after js function postback?
string alert = "< script language='javascript' >";
alert += "alert('" + message + "');";
alert += "< /script >";
response.write(alert);
Comments
Post a Comment