1

I know JavaScript and asp.net but this is first time I am using JavaScript in asp.net . I face a little problem.

My problem is JS function isvaliduser() return true or false,all time 'cObj.Save(courseObj)' is called ! I need when JS function return true only that time cObj.Save(courseObj) will call otherwise cObj.Save(courseObj) will not call.

This is my code :

 CGateway cObj = new CGateway ();
 protected void saveButton_Click(object sender, EventArgs e)
 {
     CInfo cInfoObj = new CInfo();
     cInfoObj.AName= ANameTextBox.Text;

     cObj.Save(courseObj);
 }

JavaScript :

function isvaliduser()
{
    var uid;
    var temp = document.getElementById("<%=ANameTextBox.ClientID %>");
    uid = temp.value;
    if(uid == "")
    {
       alert ("Please Enter UserName”);
       return false;
    }
    else
    {
        return true;
    }
}

ASPX:

<asp:Button ID="saveButton" runat="server" Text="Save"
OnClientClick ="javascript:isvaliduser()" />

How can I do it? Thank you.

3
  • I saw you asking about basic javascript in your previous question and someone did answer that (the same code in this question). And now that quesion is deleted. So, my point is, you should have requested for clarification right under his answer instead of deleting that question. Commented May 18, 2014 at 16:50
  • Because my that id become blocked. y? I don't know. Thats why I ask this question. clear @Raging Bull ? Commented May 18, 2014 at 16:54
  • What you mean by blocked? See the old question link in my previous comment. It says: voluntarily removed by its author. Commented May 18, 2014 at 16:57

1 Answer 1

3

You need the OnClientClick to return true or false (which if true will submit the button and if false will not). Something like this should work:

<asp:Button ID="saveButton" 
    runat="server" 
    Text="Save" 
    OnClientClick="return isvaliduser();" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.