.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

RegularExpressionValidator always fires

Posted By:      Posted Date: August 30, 2010    Points: 0   Category :ASP.Net
 
Hi friends,I am trying to use a RegularExpressionValidator for email ID text box. Everything works fine till I add an AJAX TextBoxWatermarkExtender for the same text box. I have given the WatermarkText="Email" for the text box. When I push the submit button, the RegularExpressionValidator fires and says Invalid Email ID. When I clear the same text box, no issues and the records are saved.I strongly suspect that the RegularExpressionValidator is taking the text of the watermark, ie "Email" as an invalid email ID. To test this I gave the text as "someone@website.com" for the  TextBoxWatermarkExtender and it did not fire the RegularExpressionValidator.The Email ID field in my page is not mandatory but should have a valid email ID. Have any one faced same issue and does any one have a solution to this?I am pasting the code below:<asp:TextBox ID="txtEmail" runat="server" MaxLength="50" ToolTip="Enter Email" CssClass="input" ValidationGroup="register" > </asp:TextBox> <cc1:TextBoxWatermarkExtender ID="txtEmail_TextBoxWatermarkExtender" runat="server" Enabled="True" TargetCo


View Complete Post


More Related Resource Links

Using Dynamic Property inside Html Helper with Razor fires an error

  

Hello,

I have the following with Razor:

@Html.GoogleAjax(View.GoogleAjaxKey, new String[,] { { "jquery", "1.4.2" } })

And the I get a strange error:

  'System.Web.Mvc.HtmlHelper<object>' has no applicable method named 'GoogleAjax' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

What is strange is that it works fine using:

@Html.GoogleAjax("123", new String[,] { { "jquery", "1.4.2" } })

I tried the following code line:


@View.GoogleAjaxKey

And the key is displayed just fine so the problem is how I use the value of @View.GoogleAjaxKey into Html.GoogleAjax.


Do I need to change something on my Html Helper? Here it is:


    public static MvcHtmlString GoogleAjax(this HtmlHelper helper, String key, String[,] libraries) {

      

user control derived from System.Web.UI.WebControls.WebParts only fires its OnPreRender and CreateCh

  

 I have a application which uses webparts.

So my user controls are derived from System.Web.UI.WebControls.WebParts which makes them webparts.

I have everything setup and working fine as far as the personalization and webpart goes... every thing displays and works fine.

Except that 1 of my control needs to do a bit of work in the OnPreRender event and it turns out that event only gets fired when a user is loged in the application.

So lets imagine that an administrator while logged in switched to 'Sharedscope' within the webpartmanager and then has added the usercontrol/webpart 'calendar' to the top webpart zone. This then makes the 'calendar' control viewable by all and any user who visits the page wheter logged in or anonymous.

And this works fine and very well as it is supposed to. However in the 'Calendar' user control which is derived from System.Web.UI.WebControls.WebParts I have an overiden 'OnPreRender' event like this:

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

If Not Me.DesignMode Then

Me.isloaded = True

' Test for ScriptManager and register if it exists

sm = ScriptManager.GetCurrent(Page)

If sm Is Nothing Then _

Throw New HttpException("A ScriptManager control must exist on the current page.")

Load fires twice.

  
I just noticed that after I migrated my project Load event started firing twice and even code in if(!IsPostBack) fires twice. It seems to be that the reason is that asp.net 2.0 adds Page_Load automatically for Load event and since in 1.1 version there was line like:  this.Load+=new EventHandler(thi.Page_Load); it is added second time. For some reason in my case this line wasn't removed by "Convert to Web Application" command. Just wanted to make sure that I have to do it myself and that this know bug. Thank you, Shimon.

very simple asp:RegularExpressionValidator for Email not working

  
My implementation is simple. I have a public static variable in a class called EmailHelper containing my regular expression as follows:namespace Base.Core.Utilities { public static class EmailHelper { public const string EMAIL_REGEX = @"^([a-zA-Z0-9]+([\.+_-][a-zA-Z0-9]+)*)@(([a-zA-Z0-9]+((\.|[-]{1,2})[a-zA-Z0-9]+)*)\.[a-zA-Z]{2,6})$"; } } I then have the following web controls on my page:<asp:Panel ID="pnlChangeEmail" runat="server" DefaultButton="btnChangeEmail"> <asp:Label ID="lblChangeEmail" AssociatedControlID="txtEmail" runat="server">New email:</asp:Label> <asp:TextBox ID="txtEmail" runat="server" CssClass="textfield"></asp:TextBox> <asp:LinkButton ID="btnChangeEmail" OnClick="Change_Email" runat="server" ValidationGroup="ChangeEmail" CssClass="btn"> <strong><asp:Literal runat="server" ID="litSubmit" Text='<%$ Resources: GlobalResource, SUBMIT %>' /></strong> </asp:LinkButton> <asp:RequiredFieldValidato

user control derived from System.Web.UI.WebControls.WebParts only fires its OnPreRender and CreateCh

  
I have a application which uses webparts. So my user controls are derived from System.Web.UI.WebControls.WebParts.WebPart which makes them webparts. I have everything setup and working fine as far as the personalization and webpart goes... every thing displays and works fine. Except that 1 of my control needs to do a bit of work in the OnPreRender event and it turns out that event only gets fired when a user is loged in the application. That control is also a script control so it inherits from System.Web.UI.WebControls.WebParts and also implement IScriptControl So lets imagine that an administrator while logged in switched to 'Sharedscope' within the webpartmanager and then has added the usercontrol/webpart 'calendar' to the top webpart zone. This then makes the 'calendar' control viewable by all and any user who visits the page wheter logged in or anonymous. And this works fine and very well as it is supposed to. However in the 'Calendar' user control which is derived from System.Web.UI.WebControls.WebParts I have an overiden 'OnPreRender' event like this: Protected Overrides Sub OnPreRender(ByVal e As EventArgs) If Not Me.DesignMode Then Me.isloaded = True ' Test for ScriptManager and register if it exists sm = ScriptManager.GetCurrent(Page) If sm Is Nothing Then _ Throw New HttpException("A ScriptManager contro

RegularExpressionValidator regarding on the radiobutton

  
I have RadioButton1, RadioButton2, TextBox1, TextBox2 and Button1This code for TextBox1:<asp:RegularExpressionValidator ID="RegularExpressionValidator3" ValidationExpression="^[0-9]{3}$" runat="server" ControlToValidate="TextBox1"  ErrorMessage="Vnesite!"                 ValidationGroup="ErrormessageValidationGroup"  Display="Dynamic"> <asp:Image ID="Image5" runat="server" ImageUrl="~/Images/warning.png" ImageAlign="TextTop" /></asp:RegularExpressionValidator>This code for TextBox2: <asp:RegularExpressionValidator ID="RegularExpressionValidator3" ValidationExpression="^[0-9]{3}$" runat="server" ControlToValidate="TextBox2"  ErrorMessage="Vnesite!"                  ValidationGroup="ErrormessageValidationGroup"  Display="Dynamic"> <asp:Image ID="Image5" runat="server" ImageUrl="~/Images/warning.png" ImageAlign="TextTop" /></asp:RegularExpressionValidator>I want to "Button1" writes:If RadioButton1 = True to use the first code ... ControlToValidate=

user control derived from System.Web.UI.WebControls.WebParts only fires its OnPreRender when a user

  
I have a application which uses webparts and 1 control is also a Script Control. So my user controls are derived from System.Web.UI.WebControls.WebParts.WebPart which makes them webparts. I have everything setup and working fine as far as the personalization and webpart goes... every thing displays and works fine. Except that 1 of my control needs to do a bit of work in the OnPreRender event and it turns out that event only gets fired when a user is loged in the application. That control is also a script control so it inherits from System.Web.UI.WebControls.WebParts and also implement IScriptControl So lets imagine that an administrator while logged in switched to 'Sharedscope' within the webpartmanager and then has added the usercontrol/webpart 'calendar' to the top webpart zone. This then makes the 'calendar' control viewable by all and any user who visits the page wheter logged in or anonymous. And this works fine and very well as it is supposed to. However in the 'Calendar' user control which is derived from System.Web.UI.WebControls.WebParts I have an overiden 'OnPreRender' event like this: Protected Overrides Sub OnPreRender(ByVal e As EventArgs) If Not Me.DesignMode Then Me.isloaded = True ' Test for ScriptManager and register if it exists sm = ScriptManager.GetCurrent(Page) If sm Is Nothing Then _ Throw New Ht

HttpModule which only fires a few times, then never again

  
I've got a debugpoint inside the init of my HttpModule.public void Init(HttpApplication context){            int a = 2;            int b = a;            int c = 3;}As simple as that. Basically I just put code in there to make sure it fires. So at first when I debug my site this fires a couple of times (for each file loaded). Then I go to a second page, and it fires again. After that, I never get to that breakpoint again. Why is this?I'm having trouble with SessionState in my httpmodule on this specific site. context.Current.Session is null. I've tried both PreRequestHandlerExecute and BeginRequest. But the first thing I want to fix is to make the HttpModule to ALWAYS fire.

RegularExpressionValidator - trailing blanks

  
This is crazy ... ALL I want to do is check for 10 or less AlphaNumeric characters, and ignore any trailing whitespace in the text box I am checking ... I am using this: ValidationExpression   ="^[a-zA-Z0-9]{1,10}$". The validator, however, is returning 10 characters, plus 4 white spaces as an error (ie, "abcfdsitnr    "  ... which should not be an error).  Can anyone help? please? Thanks.

RegularExpressionValidator and the new AsyncFileUpload

  
 Hi,I try to valide the new AJAX AsyncFileUpload control but it seems not to work : Control 'AsyncFileUpload1' referenced by the ControlToValidate property of 'REV1' cannot be validated.<cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" Width="400px"                     ThrobberID="throbber" />                <asp:Label ID="throbber" Style="display: none" runat="server"><img alt="loading" src="images/upload.gif" /></asp:Label><asp:RegularExpressionValidator                    ID="REV1" runat="server" ErrorMessage=" File invalid"                    ControlToValidate="AsyncFileUpload1" ValidationExpression="(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[bB][mM][pP]|[pP][nN][gG])$)"                    Display="Dynamic" Text="

HTTP Handler ProcessRequest only Fires First Time

  

I have a JavaScript method which is called whenever a modal window closes. The JavaScript method calls an HTTP Handler to run a server side function. When I close the window the first time, the code behind runs. When I close it a second time, I can see the JavaScript method run, I am getting an XMLHTTPRequest object, but the code behind does not run again. What am I missing? Thanks.

 

            function createXMLHttpRequest() {
                try { return new XMLHttpRequest(); } catch (e) { }
                try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { }
                try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
                return null;
            }

            function ClearDocumentSession() {

                var xmlHttpReq = createXMLHttpRequest();
                xmlHttpReq.open("GET", "http://localhost:56331/Handlers/AjaxHandler.ashx", false);
                xmlHttpReq.send(null);
            }

 

The handle

public class AjaxHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
           //  context.Response.ContentType = "text/html";
             HttpContext.Current.Session[

AjaxControlToolkit TextBoxWatermarkExtender fires TextChanged Event on every postback

  

I haven't been able to find anything on the net about this yet. A project that used to work fine all of a sudden started having trouble with a couple users. The TextBoxWatermarkExtenders for these users are now always firing the TextChanged event of the textboxes they are assigned to for every postback. I don't think this is what they are supposed to do. They didn't use to do this. Has anyone else experienced this? I can add code to ignore these unintentional events, but I would like to know why all of a sudden the change in behavior.

Any information about this would be greatly appreciated.

Thanks


GridView RowDeleting event fires twice !

  

I'm facing some annoying GridView behavior where it fires the RowDeleting event twice.

I'm doing the very normal (logical) steps for deleting a row from a GridView. Here is what I'm doing:

1- my test Page_Load  method

protected void Page_Load(object sender, EventArgs e)
{

	GridView1.DataSource = GetDataTable();
	GridView.DataBind();
}
	// Note: GetDataTable() returns a non-null DataTable object.
	// Also the DataTable has more than 1 row
	// (i.e. everything is fine with the datatable)


2- the GridView has a Delete Command Field.

3- on tracing I've noticed my RowDeleting event gets fired twice! (also I used a static counter to see how many times the event gets fired when clicking on the GridView delete button, which was also confirmed it that it's counting 2 per each click).

Am I doing something wrong? please help

 


Problems with RegularExpressionValidator

  

Hi,

I have a simple test page with the following:

    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
        ControlToValidate="TextBox1" 
        ErrorMessage="MELLOM 1 og 200" 
        ValidationExpression="^.{1,20}$"/>
    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="531px"></asp:TextBox>

As you probably see, I'm trying to validate if the field contains BETWEEN 1 and 200 "anythings". The problem is that it triggers correctly if there are more than 20 "anythings" in the text box, but not if there are zero :S

Anyone see what the problem might be?


Thanks!


Is RegularExpressionValidator.IsValid ok to use server side?

  

I am using regular expression validators.  I know that I have to validate client side and server side. 


Is it ok to use RegularExpressionValidator.IsValid on the server side to see if the field is valid?  Do I have to use RegularExpressionValidator.Validate before RegularExpressionValidator.IsValid is set?


ProgressChanged event randomly fires with BackgroundWorker?

  
I'm using a background worker for a Windows Form app I'm writing - .NET 3.5.

I'm using the background worker so that I can keep my user interface responsive (i.e. don't need to use Application.DoEvents) specifically when using Progressbar and status messages.  However, what I've noticed is that during my DoWork method when I do a .ReportProgress(somevalue, somemsg) it doesn't fire the ProgressChanged event immediately, it often fires longer after I've moved onto other processing. 

The end result is that the Progress bar gets update later than the actual processing being done, in some cases it's way out of synch.  So at this point I'm sorta wondering why I should even bother with Background worker threads when an Application.DoEvents on the main thread will accomplish a more accurate synch'd UI update??

Am I missing something?  Is my choice of BackgroundWorker a bad one?  Should I just go with System.Threading and manage all the work around that rather than trying the more simple BackgroundWorker?

Thanks, Rob.

threading timers fires few seconds before the actual due time

  

Hi,

We're getting following problem while using system.threading.timer ( .net framework 2.0 ) from a Windows service.

There are around 12 different timer objects..
Each timer has due time and interval. This is set correctly.
It is observed that after 3 to 4 hours, the timers start signalling before their interval elapses. For example if the timer is supposed to signal at 4:59:59, it gets signalled at 4:59:52, 7 seconds earlier.
Can someone tell me what is the cause for this behavior and what is the solution for that ?

Thanks, Gayatri


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend