6 Replies - 2239 Views - Last Post: 29 May 2014 - 02:58 AM Rate Topic: -----

#1 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 136
  • Joined: 10-August 12

Javascript Recognition Issue

Posted 14 April 2014 - 07:38 AM

Hello,

I am trying to figure out something with the client id property of ASP.Net. This past week when using the below code everything worked perfectly. The validation and information all processes properly. For some unknown reason when I come in today the <%= %> portion of the ASP.Net ClientID call within the Javascript function doesn't allow the javascript to be recognized. If I just set an alert box in where the code for ASP.net exists it works fine but the moment I put the ASP.net code in the document.getElementByID portion it actually takes the plus/minus sign off the javascript function in Visual Studio and it no longer recognizes the javascript function at all. Any ideas? I have already rebuilt the project - closed Visual Studio and reopened and the same problem persists. Here is the javascrtip and button call:

        function CheckUsername(txt) {
            var text = txt.value;
            var letters = /^[0-9a-zA-Z_]+$/;
            if (text != "")
            {
                if (letters.test(text)) {
                }
                else {
                    document.getElementById('/</%= lblErrorMessage.ClientID /%/>').innerText = "Invalid - Cannot Contain Special Characters Ex:" & '&^$#(){}@!$' & "'";
                }
            }
        }

            <div class="col-xs-3" id="uname">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:TextBox ID="txtUsername" placeholder="Chosen Username" AutoPostBack="true" onblur="CheckUsername(this); RunUsernameCheck();" runat="server" class="form-control" MaxLength="8"></asp:TextBox>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>



Is This A Good Question/Topic? 0
  • +

Replies To: Javascript Recognition Issue

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 679
  • View blog
  • Posts: 2,980
  • Joined: 03-December 12

Re: Javascript Recognition Issue

Posted 14 April 2014 - 08:56 AM

Your function call appears to have a ' mismatch. If I am reading correctly, that error in itself would cause the Javascript to fail.
Was This Post Helpful? 0
  • +
  • -

#3 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 136
  • Joined: 10-August 12

Re: Javascript Recognition Issue

Posted 14 April 2014 - 09:54 AM

Where do you think you are seeing the issue? Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 679
  • View blog
  • Posts: 2,980
  • Joined: 03-December 12

Re: Javascript Recognition Issue

Posted 14 April 2014 - 10:25 AM

innerText = "Invalid - Cannot Contain Special Characters Ex:" & '&^$#(){}@!$' & "'";

This post has been edited by astonecipher: 14 April 2014 - 10:28 AM

Was This Post Helpful? 0
  • +
  • -

#5 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 136
  • Joined: 10-August 12

Re: Javascript Recognition Issue

Posted 14 April 2014 - 12:24 PM

View Postastonecipher, on 14 April 2014 - 10:25 AM, said:

innerText = "Invalid - Cannot Contain Special Characters Ex:" & '&^$#(){}@!$' & "'";



Changing it to this still does not help:

     if (letters.test(text)) {
            }
            else {
               document.getElementById('<%= lblErrorMessage.ClientID %>').innerHTML = "Invalid - Cannot Contain Special Characters Ex: &^$#(){}@!$ ";
            }


Was This Post Helpful? 0
  • +
  • -

#6 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: Javascript Recognition Issue

Posted 14 April 2014 - 01:24 PM

Try not escaping the /</% and /%/>. This will first be processed by the server and this is not valid asp.net tags.

Sorry, I didn't notice your last example.

This post has been edited by laytonsdad: 14 April 2014 - 01:31 PM

Was This Post Helpful? 0
  • +
  • -

#7 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 396
  • Joined: 04-January 11

Re: Javascript Recognition Issue

Posted 29 May 2014 - 02:58 AM

Do you really need to be using javascript?

If not necessarily, why don't you use the RegularExpressionValidator of ASP.NET?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1