|
Rank: Member Groups: Member
Joined: 7/17/2008 Posts: 13
|
I have a dialog which includes a validator on a listbox in the dialog. When clicking on the ok button, if my validator fails, is there something I need to set or do to keep the dialog open?
thanks
chris
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi Chris, I believe you can do that by handling the dialog's ClientSideOnAccept event. It will be something like this:
Code: HTML/ASPX
<eo:Dialog ClientSideOnAccept="accept_handler" ...>
.....
</eo:Dialog>
Code: JavaScript
function accept_handler()
{
//Perform all validations and returns false if any of them fail
//Returning false from this handler prevents the dialog from
//closing
if (!Page_ClientValidate())
return false;
}
Please let us know if this solves the problem. Thanks!
|
|
Rank: Member Groups: Member
Joined: 7/17/2008 Posts: 13
|
The suggestion didn't work for me.
Here is an example:
html/aspx
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Dialog.aspx.cs" Inherits="EOTest.Dialog" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Dialog test</title> </head> <body> <form id="form1" runat="server"> <%@ register assembly="EO.Web" namespace="EO.Web" tagprefix="eo" %> <div class="FieldValue"> <table> <tr> <td> Title: </td> </tr> <tr> <td> <a href="javascript:eo_GetObject('UserSelectionDialog').show(true);">(change)</a> </td> </tr> </table> </div> <eo:Dialog ID="UserSelectionDialog" runat="server" BackColor="#EBEBEB" Height="100px" Width="466px" AcceptButton="btnAddUserOwner" AcceptButtonPostBack="True" ControlSkinID="None" FooterHtml="Dialog Footer" HeaderHtml="Change User Owner" ClientSideOnAccept="accept_handler"> <ContentTemplate> <div class="FieldLabelDiv"> User Owner: </div> <div class="FieldValue FieldValueDD"> <asp:ListBox ID="msOwner" runat="server" SelectionMode="Multiple" Rows="10"></asp:ListBox> <asp:CustomValidator ID="CVddChangeGroup" runat="server" ErrorMessage="This field requires a selection." OnServerValidate="msOwner_ServerValidate"></asp:CustomValidator><span id="spanChangeOwnerRequired" runat="server" visible="false">1</span> </div> </ContentTemplate> <FooterTemplate> <div class="FieldLabelDiv"> </div> <div class="FieldValue"> <asp:Button ID="btnAddUserOwner" runat="server" Text="Ok" Width="75px" /> <%--OnClick="btnAddUserOwner_Click"--%> </div> </FooterTemplate> <HeaderStyleActive CssText="padding-right: 3px; padding-left: 8px; font-weight: bold; font-size: 10pt; background-image: url(00020213); padding-bottom: 3px; color: white; padding-top: 0px; font-family: 'trebuchet ms';" /> <BorderImages BottomBorder="00020212" BottomLeftCorner="00020207" BottomRightCorner="00020208" LeftBorder="00020210" RightBorder="00020211" TopBorder="00020209" TopLeftCorner="00020201" TopLeftCornerBottom="00020203" TopLeftCornerRight="00020202" TopRightCorner="00020204" TopRightCornerBottom="00020206" TopRightCornerLeft="00020205" /> <FooterStyleActive CssText="padding-right: 4px; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; padding-top: 4px; font-family: tahoma" /> <ContentStyleActive CssText="padding-right: 4px; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; padding-top: 4px; font-family: tahoma" /> </eo:Dialog> <span id="spanShowAll" runat="server" visible="false">0</span><span id="spanObjectType" runat="server" visible="false">0</span>
<script language="javascript" type="text/javascript">
function accept_handler() { //Perform all validations and returns false if any of them fail //Returning false from this handler prevents the dialog from //closing if (!Page_ClientValidate()) { alert('inside'); return false; } }
</script>
</form> </body> </html>
C#
using System; using System.Data; using System.Configuration; using System.Collections; using System.Text; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
namespace EOTest {
public partial class Dialog : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) { setUserDropDown(); } }
private void setUserDropDown() { msOwner.Items.Insert(0, new ListItem("11111", "1")); msOwner.Items.Insert(0, new ListItem("22222", "2")); msOwner.Items.Insert(0, new ListItem("33333", "3")); msOwner.Items.Insert(0, new ListItem("(All)", "")); }
protected void msOwner_ServerValidate(object source, ServerValidateEventArgs args) { if (msOwner.SelectedIndex == -1) { args.IsValid = false; } } } }
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi, Sorry that we did not know you are using server side code to validate input. You can change your Page_Load handler to the following code to keep the dialog open when the validation fails:
Code: C#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
setUserDropDown();
}
else
{
//Validate input. This will call your msOwner_ServerValidate
Page.Validate();
//Show the dialog if validation fails, otherwise closes the dialog
if (!Page.IsValid)
UserSelectionDialog.InitialState = EO.Web.DialogState.Visible;
else
UserSelectionDialog.InitialState = EO.Web.DialogState.Hidden;
}
}
Since the validation is done on the server side, a postback must occur. This would cause the dialog to briefly disappear and then re-appear, just like refreshing any other page. Hope this helps! Thanks
|
|
Rank: Member Groups: Member
Joined: 7/17/2008 Posts: 13
|
This works.
Thanks.
|
|