Ask a Question related to ASP.NET Building Controls, Design and Development.
-
HipHop #1
Validator message disappeared after post back
Hi,
I have a compositecontrol contain a textbox (txtPhoneNumber) and a
RegularExpressionValidator.
I tested in a page, the validation seems work fine until post back, the
validation message disappeared after post back while the text in the phone
number still remain the invalid format.
Could anybody please help me.
Thanks.
HipHop Guest
-
Dragging rows without a post back to the server.
I have been able to create a datagrid that is able to click and drag from one row and drop it onto another to move it above the row dropped on. The... -
post the result back to same page??
<html> <body> <Form action="calc.asp" method="post" name="calc"> <P>NUM1: <input type="text" name="num1"> <P>NUM2: <input type="text"... -
Post back
hello all, I have a simple question. on my .aspx page I have bunch of textbox, and dropdowns. One of the dropdown2 has postback = true. When the... -
Post back and control focus issues
Hi, This might help : http://www.developer.com/net/asp/article.php/2237431 Natty Gur, CTO Dao2Com Ltd. 28th Baruch Hirsch st. Bnei-Brak... -
post back doesn't work
On Tue, 22 Jul 2003 20:01:44 -0400, "shimonsim@talamus.com" <estshim@att.net> wrote: I bet you have somewhere in that form an html submit... -
Walter Wang [MSFT] #2
RE: Validator message disappeared after post back
Hi HipHop,
Which control caused the post back? Is its CausesValidation set to true?
Based on my test code:
namespace myns
{
public class Class1 : CompositeControl
{
private TextBox m_txtPhoneNumber;
private RegularExpressionValidator m_vldPhoneNumber;
protected override void CreateChildControls()
{
Controls.Clear();
m_txtPhoneNumber = new TextBox();
m_txtPhoneNumber.ID = "txtPhoneNumber";
Controls.Add(m_txtPhoneNumber);
m_vldPhoneNumber = new RegularExpressionValidator();
m_vldPhoneNumber.ID = "vldPhoneNumber";
m_vldPhoneNumber.ValidationExpression = @"\d+";
m_vldPhoneNumber.ControlToValidate = "txtPhoneNumber";
m_vldPhoneNumber.ErrorMessage = "Invalid phone number";
m_vldPhoneNumber.EnableClientScript = true;
Controls.Add(m_vldPhoneNumber);
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%@ Register TagPrefix="c" Namespace="myns" Assembly="__code" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<c:Class1 ID="c1" runat="server" />
<asp:Button ID="Button1" runat="server" CausesValidation="False"
OnClick="Button1_Click"
Text="Button" /></div>
</form>
</body>
</html>
This reproduces the exact issue you described. However, this is expected
since the button's CausesValidation is turned off and the validation will
not occur.
If this is not your case, would you please post your code here? Thanks.
Merry Christmas and Happy New Year!
Sincerely,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
[url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/url]
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
[url]http://msdn.microsoft.com/subscriptions/support/default.aspx[/url].
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] Guest
-
Walter Wang [MSFT] #3
RE: Validator message disappeared after post back
Hi HipHop,
I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.
Have a great day!
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] Guest
-
HipHop #4
Re: Validator message disappeared after post back
Walter, Thank you for your answer. However, I don't have buttons, all I have
is another textbox which causevalidation set to false, but AutoPostBack set
to true in order to trigger TextChanged event.
Here is my code for Conposite Control EmailTextBox (Let's use Email instead
of PhoneNumber),
====================begin of EmailTextBox =====
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace EnterpriseLibrary.WebControls
{
[DefaultProperty("Value")]
[ToolboxData("<{0}:ncEmailTextBox runat=server></{0}:ncEmailTextBox>")]
public class ncEmailTextBox : CompositeControl
{
private TextBox txtEmail = new TextBox();
private RegularExpressionValidator VldtrEmail;
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Value
{
get
{
return txtEmail.Text;
}
set
{
EnsureChildControls();
txtEmail.Text = value;
}
}
protected override void CreateChildControls()
{
txtEmail.ID = this.ID + "_Email";
txtEmail.Width = 140;
VldtrEmail = new RegularExpressionValidator();
VldtrEmail.ID = this.ID + "_VldtrEmail";
VldtrEmail.ControlToValidate = txtEmail.ID;
VldtrEmail.ValidationExpression =
@"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$";
VldtrEmail.Text = "Invalid email format.";
VldtrEmail.Display = ValidatorDisplay.Static;
this.Controls.Add(txtEmail);
this.Controls.Add(VldtrEmail);
base.CreateChildControls();
}
public override void RenderControl(System.Web.UI.HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
txtEmail.RenderControl(writer);
VldtrEmail.RenderControl(writer);
writer.RenderEndTag(); // td
writer.RenderEndTag(); // tr
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.RenderEndTag();//td
writer.RenderEndTag();//tr
writer.RenderEndTag(); // table
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
}
}
============ end of EmailTextBox ==================
Code for the Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="play.aspx.cs"
Inherits="play" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr><td>Composite Control Email:</td><td><nc:ncEmailTextBox ID="Email"
runat="server" /></td></tr>
<tr><td>Some TextBox with AutoPostBack:</td><td><asp:TextBox ID="TextBox1"
runat="server" AutoPostBack="true"
OnTextChanged="TextBox1_TextChanged"></asp:TextBox></td></tr>
</table>
</form>
</body>
</html>
"Walter Wang [MSFT]" <wawang@online.microsoft.com> wrote in message
news:g1sVKQnKHHA.2488@TK2MSFTNGHUB02.phx.gbl...> Hi HipHop,
>
> I am interested in this issue. Would you mind letting me know the result
> of
> the suggestions? If you need further assistance, feel free to let me know.
> I will be more than happy to be of assistance.
>
> Have a great day!
>
> Regards,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
HipHop Guest
-
Walter Wang [MSFT] #5
Re: Validator message disappeared after post back
Hi HipHop,
To make the validator work in or before a postback, the control who will
cause the postback must have CausesValidation set to true. Would you please
set the TextBox's CausesValidation to true and test it again:
<asp:TextBox ID="TextBox1" runat="server" CausesValidation="true"
AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox></td>
I've tested it on my side using your code, if the CausesValidation is set
to true, the page will not be posted back since client-side validation is
enabled and the validation result is false, therefore it prevents the page
being posted back.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] Guest
-
HipHop #6
Re: Validator message disappeared after post back
Thanks, it works. But what if I have a calendar that required a post back to
trigger the server event, the error message will disappear after a post
back.
Of course it will come back if user did not correct them and push the summit
button which I check if the page is valid.
Is this the only way?
"Walter Wang [MSFT]" <wawang@online.microsoft.com> wrote in message
news:ocjIwTHMHHA.2300@TK2MSFTNGHUB02.phx.gbl...> Hi HipHop,
>
> To make the validator work in or before a postback, the control who will
> cause the postback must have CausesValidation set to true. Would you
> please
> set the TextBox's CausesValidation to true and test it again:
>
> <asp:TextBox ID="TextBox1" runat="server" CausesValidation="true"
> AutoPostBack="true"
> OnTextChanged="TextBox1_TextChanged"></asp:TextBox></td>
>
>
> I've tested it on my side using your code, if the CausesValidation is set
> to true, the page will not be posted back since client-side validation is
> enabled and the validation result is false, therefore it prevents the page
> being posted back.
>
>
> Regards,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
HipHop Guest
-
Walter Wang [MSFT] #7
Re: Validator message disappeared after post back
Hi HipHop,
I've done some research (using Reflector to dig into the implementation of
Calendar and Button controls), unfortunately it's not possible to extend
the Calendar to support CausesValidation function as in Button.
In the Button, it uses customized PostBackOptions to indicate that the
generated javascript to postback the page will validate the page first. The
Calendar control's relevant functions are private and not possible to
override.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] Guest
-
Walter Wang [MSFT] #8
Re: Validator message disappeared after post back
Hi Hiphop,
Not sure if you've seen my previous reply. Please feel free to let me know
if you want more information on it. Thanks.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] Guest



Reply With Quote

