Javascript form validation! RRS feed

  • Question

  • User-1097933300 posted

    Hi guys,

    I am a beginer using Javascript in .Net.
    I have a .Net mobile page that contains a simple mobile form with some textboxes and a submit button. What I'm trying to do is that I wanna write a script that checks the value of textboxes to make sure they are not empty and if otherwise write an error message on the screen. I have used the "Page.ClientScriptStartupScript()" but still have some confusion.

    any help is much appreciated.
    Thanks in advance

    Wednesday, April 18, 2007 4:28 AM

All replies

  • User731069546 posted

    I never been able to call javascript on client side using mobile controls. If you using regular web controls then you can use something like

     ctr.Attributes.Add("onlick", "your javascript fn")

    You need to use conetnt template of a device specific to send javascrip to the client.

    But why do all this when you can do the validation on the server side after the postback from client, using your regular mobile control? If textbox is empty send an error back to the client. It is very simple. For example change the text of a mobile label control to the Error Message, when textbox is empty.

     Or you can use the validator mobile controls. Off course both these solutions require a postback to the server.

    Wednesday, April 18, 2007 4:34 PM
  • User-1097933300 posted


    Thanks for your reply.
    I agree that using mobile validation tools are so easy and comfortable to work with, however, I gotta use client-side validation in order to reduce server time consumption. To be honest I kinda am forced to do that. I have used the ContentTemplate in DeviceSpecific in a mobile form. The problem is that I have put the name of the validation function in the OnClick ttibute of the submit button, and when it is clicked either it gives an error that my function name is not defined in the context or sometimes the page runs but nothing happens.

    If you have any idea what is going wrong or have a sample code for this, it would help a lot.
    Thanks in advance.

    Thursday, April 19, 2007 4:14 AM
  • User1634317999 posted
    Can you please post your code? It seems that you haven't used the DeviceSpecific and Command Controls correctly.
    Thursday, April 19, 2007 10:43 AM