TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Manolo Lopez
NA
1
3k
Multiview and custom validators not firing
Oct 18 2011 8:14 AM
I have a custom validator in a second view but it is not fired when the page is submitted.
I load the page with a multiview containing two views. When the page loads, the first view is shown. Then I press a button and the second view is shown but when the data is submitted, it seems that the validators are not active.
Any logic or explanation?
There is no problem is the second view is shown from the beginning.
Example:
------------
ASPX.CS
------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MultiView1.SetActiveView(View1);
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
MultiView1.SetActiveView(View2);
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
TextBox1.Text = "OK";
}
else
{
TextBox1.Text = "NO";
}
}
}
------------
ASPX
------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:MultiView ID="MultiView1" runat="server">
<asp:View ID="View1" runat="server">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Css/img/add.png"
onclick="ImageButton1_Click" />
</asp:View>
<asp:View ID="View2" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="CustomValidator"
onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
UseSubmitBehavior="False" />
</asp:View>
</asp:MultiView>
</div>
</form>
</body>
</html>
Reply
Answers (
1
)
Directive used in Custom Controls
Constructor and Destructor