Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, all. I got stuck...here..

Let me simplify my problem..

 

I added One TextBox, and Required Validator associated with the textbox.

And, Submit button.

 

When submit is clicked it should do some thing before submit.

So, when button clicked javascript function "SaveData()" must be called.

 

So, I added following code to Page_Load event.

 

this.btSubmit.Attributes.Add("onclick","return SaveData() ;") ;

 

After adding this, validator doesn't work! Event with empty textbox, it still submit to server without stopping..

 

SaveData() is this.

<script language="javascript">

<!--

function SaveData()

{

if (!true)

return false ;

try{

//do nothing

}catch(e){}

return true ;

}

-->

</script>

 

and the client side code generated is following.

 

<input type="submit" name="Button1" value="Button" onclick="return SaveData() ;if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="Button1" />

 

It seems validator doesn't work if there is javascript function call.

How can I do both, calling javascript code and using validator?

 

Any comment will help!

Thank you.

Sun Certified Web component Developer,

Microsoft Certified Solution Developer .NET,

Software Engineer

Posted

Thank you I got it.

I solve with following..

 

this.btSumit.Attributes.Add("onclick","if(!SaveData()){return false;}") ;

Sun Certified Web component Developer,

Microsoft Certified Solution Developer .NET,

Software Engineer

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...