Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / April 2004

Tip: Looking for answers? Try searching our database.

JS: Validation + ASPX

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom - 21 Apr 2004 07:46 GMT
Hi,

I am crazy to fix the javascript bug for the past 2 days.

Here is the code:

[code]
ASPX code -------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><HEAD><title>Test</title><meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta content="JavaScript" name="vs_defaultClientScript"><meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"><script language="javascript">
            function CheckInput()
                {
                   var ft = document.all;
                    if(isEmpty(ft.lastname.value))
                    {
                    window.alert('Please Enter Last Name!');
                    ft.lastname.focus();
                    return false;
                    }
                }
        </script></HEAD><BODY><form id="contact" onsubmit="javascript:return CheckInput();" method="post" runat="server"><TABLE cellSpacing="0" cellPadding="0" width="100%" border="0"><TBODY><TR><td><asp:textbox id="lastname" Runat="server" CssClass="form" Wrap="False"></asp:textbox><asp:requiredfieldvalidator id="RequiredFieldValidatorLastName" runat="server" ErrorMessage="Please input last name!"
                                        Display="None" ControlToValidate="lastname" EnableViewState="False"></asp:requiredfieldvalidator></td><td><asp:button id="btnSubmit" Runat="server" cssclass="button_3" text="Submit"></asp:button></td></TR></TBODY></TABLE></form></BODY></HTML>

C# code ------

        protected System.Web.UI.WebControls.TextBox lastname;
        protected System.Web.UI.WebControls.Button btnSubmit;
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidatorLastName;
   
        private void Page_Load(object sender, System.EventArgs e)
        {
            if(!IsPostBack)
            {
            }
        }

        #region Web Form
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
       
        private void InitializeComponent()
        {    
            this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion

        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            if(Page.IsValid)
            {
            }
        }
[/code]

When I submit the form, there is no pop up dialog box to alert me.

The error message showed in IE6 is that "There must be an object".

It means it cannot locate id=lastname.

How should I fix it? Thanks for help.
bruce barker - 21 Apr 2004 20:52 GMT
your need to define isEmpty

-- bruce (sqlwork.com)

> Hi,
>
[quoted text clipped - 7 lines]
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
><HTML><HEAD><title>Test</title><meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta
content="JavaScript" name="vs_defaultClientScript"><meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema"><script language="javascript">
> function CheckInput()
> {
[quoted text clipped - 7 lines]
> }
> </script></HEAD><BODY><form id="contact" onsubmit="javascript:return CheckInput();" method="post" runat="server"><TABLE cellSpacing="0"
cellPadding="0" width="100%" border="0"><TBODY><TR><td><asp:textbox
id="lastname" Runat="server" CssClass="form"
Wrap="False"></asp:textbox><asp:requiredfieldvalidator
id="RequiredFieldValidatorLastName" runat="server" ErrorMessage="Please
input last name!"
> Display="None" ControlToValidate="lastname" EnableViewState="False"></asp:requiredfieldvalidator></td><td><asp:button
id="btnSubmit" Runat="server" cssclass="button_3"
text="Submit"></asp:button></td></TR></TBODY></TABLE></form></BODY></HTML>

> C# code ------
>
[quoted text clipped - 38 lines]
>
> How should I fix it? Thanks for help.
Shawn B. - 26 Apr 2004 20:12 GMT
Add the following code to your script tag:

function IsEmpty(value) {
  if (value == '') {
     return true;
  }
  return false;
}

Thanks,
Shawn

> Hi,
>
[quoted text clipped - 7 lines]
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
><HTML><HEAD><title>Test</title><meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta
content="JavaScript" name="vs_defaultClientScript"><meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema"><script language="javascript">
> function CheckInput()
> {
[quoted text clipped - 7 lines]
> }
> </script></HEAD><BODY><form id="contact" onsubmit="javascript:return CheckInput();" method="post" runat="server"><TABLE cellSpacing="0"
cellPadding="0" width="100%" border="0"><TBODY><TR><td><asp:textbox
id="lastname" Runat="server" CssClass="form"
Wrap="False"></asp:textbox><asp:requiredfieldvalidator
id="RequiredFieldValidatorLastName" runat="server" ErrorMessage="Please
input last name!"
> Display="None" ControlToValidate="lastname" EnableViewState="False"></asp:requiredfieldvalidator></td><td><asp:button
id="btnSubmit" Runat="server" cssclass="button_3"
text="Submit"></asp:button></td></TR></TBODY></TABLE></form></BODY></HTML>

> C# code ------
>
[quoted text clipped - 38 lines]
>
> How should I fix it? Thanks for help.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.