Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

controlling the click event of linkbutton

Status
Not open for further replies.

rotsey

Programmer
Nov 23, 2004
135
AU
Hi,

I have a linkbutton with some server codee behind it.

I want to be able to attach a javascript function to it that does some validation and then if returns true then to go on and process the server code.

How would I do this because the onclick property of the linkbutton is set to the server vb function. How do call the js function???

any help appreciated?

Thanks
rotsey
 
If you add a ; to the end of the onclick event that you add then when the click happens, both your function and the server funtion should execute. e.g.
Code:
LinkButton1.Attributes.Add("onclick", "MyJavascriptFunction();")

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I tried that and it does execute both but I want it to not fire the server code if the js returns false.

Like this

Code:
      function UpdateCourse(btn) {"
       if (ValidateCourse()==true)"
            return true;"
         else"
           return false;"
        }

Is this possible?
 
in your attributes.add do you have...

Code:
LinkButton1.Attributes.Add("onclick", "return UpdateCourse(btn);")

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top