Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. ASP & JavaScript

ASP & JavaScript

Scheduled Pinned Locked Moved ASP.NET
csharpjavajavascripthtmlcss
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    future3839
    wrote on last edited by
    #1

    Hi, I have a few textbox on my form and would like to validate it through Java script. I know there is RequiredFieldValidator in asp.net but I would like to do that by Javascript. this is my code

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApplication1.Presentation.Register" %>

    <!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>
    <script language= "javascript" type="text/javascript"></script>

    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
        }
        .style3
        {
            width: 153px;
            height: 17px;
        }
        .style5
        {
            width: 151px;
        }
        .style6
        {
            width: 91px;
        }
        .style7
        {
            height: 23px;
        }
        .style8
        {
            height: 26px;
        }
        .style9
        {
            height: 25px;
        }
        .style10
        {
            width: 151px;
            height: 23px;
        }
        .style11
        {
            width: 91px;
            height: 23px;
        }
    </style>
    <script language="javascript" type="text/javascript">
    

    // <![CDATA[

        function StId\_txt\_onclick() {
    
        }
    

    // ]]>
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

        <table class="style1">
            <tr>
                <td colspan="4" class="style7">
                    <asp:Label ID="PrsnInfo\_lbl" runat="server" Text="Personal Information"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:Label ID="StId\_lbl" runat="server" Text="Student ID" Font-Names="Arial" 
                        Font-Size="Smaller"></asp:Label>
                </td>
                <td class="style9" colspan="3">
                    <input id="StId\_txt" runat="server"
                        style="border: 0.3px inset #000000; height: 20px; width: 137px;" type="text" />
                    <asp:RequiredFieldValidator ID="Required
    
    L K 2 Replies Last reply
    0
    • F future3839

      Hi, I have a few textbox on my form and would like to validate it through Java script. I know there is RequiredFieldValidator in asp.net but I would like to do that by Javascript. this is my code

      <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApplication1.Presentation.Register" %>

      <!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>
      <script language= "javascript" type="text/javascript"></script>

      <style type="text/css">
          .style1
          {
              width: 100%;
          }
          .style2
          {
          }
          .style3
          {
              width: 153px;
              height: 17px;
          }
          .style5
          {
              width: 151px;
          }
          .style6
          {
              width: 91px;
          }
          .style7
          {
              height: 23px;
          }
          .style8
          {
              height: 26px;
          }
          .style9
          {
              height: 25px;
          }
          .style10
          {
              width: 151px;
              height: 23px;
          }
          .style11
          {
              width: 91px;
              height: 23px;
          }
      </style>
      <script language="javascript" type="text/javascript">
      

      // <![CDATA[

          function StId\_txt\_onclick() {
      
          }
      

      // ]]>
      </script>
      </head>
      <body>
      <form id="form1" runat="server">
      <div>

          <table class="style1">
              <tr>
                  <td colspan="4" class="style7">
                      <asp:Label ID="PrsnInfo\_lbl" runat="server" Text="Personal Information"></asp:Label>
                  </td>
              </tr>
              <tr>
                  <td class="style9">
                      <asp:Label ID="StId\_lbl" runat="server" Text="Student ID" Font-Names="Arial" 
                          Font-Size="Smaller"></asp:Label>
                  </td>
                  <td class="style9" colspan="3">
                      <input id="StId\_txt" runat="server"
                          style="border: 0.3px inset #000000; height: 20px; width: 137px;" type="text" />
                      <asp:RequiredFieldValidator ID="Required
      
      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      FWIW: While client-side validation may improve the user experience, you should always have validation on the server-side just to be safe. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      1 Reply Last reply
      0
      • F future3839

        Hi, I have a few textbox on my form and would like to validate it through Java script. I know there is RequiredFieldValidator in asp.net but I would like to do that by Javascript. this is my code

        <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApplication1.Presentation.Register" %>

        <!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>
        <script language= "javascript" type="text/javascript"></script>

        <style type="text/css">
            .style1
            {
                width: 100%;
            }
            .style2
            {
            }
            .style3
            {
                width: 153px;
                height: 17px;
            }
            .style5
            {
                width: 151px;
            }
            .style6
            {
                width: 91px;
            }
            .style7
            {
                height: 23px;
            }
            .style8
            {
                height: 26px;
            }
            .style9
            {
                height: 25px;
            }
            .style10
            {
                width: 151px;
                height: 23px;
            }
            .style11
            {
                width: 91px;
                height: 23px;
            }
        </style>
        <script language="javascript" type="text/javascript">
        

        // <![CDATA[

            function StId\_txt\_onclick() {
        
            }
        

        // ]]>
        </script>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>

            <table class="style1">
                <tr>
                    <td colspan="4" class="style7">
                        <asp:Label ID="PrsnInfo\_lbl" runat="server" Text="Personal Information"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style9">
                        <asp:Label ID="StId\_lbl" runat="server" Text="Student ID" Font-Names="Arial" 
                            Font-Size="Smaller"></asp:Label>
                    </td>
                    <td class="style9" colspan="3">
                        <input id="StId\_txt" runat="server"
                            style="border: 0.3px inset #000000; height: 20px; width: 137px;" type="text" />
                        <asp:RequiredFieldValidator ID="Required
        
        K Offline
        K Offline
        keyur satyadev
        wrote on last edited by
        #3

        I agree that server side validation is safe. still if you wish to proceed then please find below example to validate textbox. var txtValue = document.getElementById(<"%txt1.ClientID%">).value; if(txtValue==null || txtValue='') { alert('Please enter value in textbox.'); //message should be depends on requirement. return false; } Let me know still if you have any doubts.

        Regards Keyur Satyadev

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups