Problem in calling javascript function on the Onclick event of the Button webcontrol

L

Lakshmi Murthy

Hi

I am using a javascript in my aspx page and i want to call a javascript function on my <asp:Button> control.I am calling the javascript function in the onclick attribute of the button as shown below

<script lang="Javascript"
function Test(

var Objtxt = document.getElementById("TextBox1")
if (Objtxt!=null)
Objtxt.value ="test


</script><asp:Button id="Button2" runat="server" onclick="javascript:Test();"></asp:Button

An error is getting generated as below

Compiler Error Message: BC30456: 'javascript' is not a member of 'ASP.WebForm1_aspx'

Please let me know what is wrong in my code

Thanks in Advanc
Regard
Lakshm
 
K

Ken Cox [Microsoft MVP]

Try inserting the onclick code in the Page_Load event like this?

private void Page_Load(object sender, System.EventArgs e)
{
Button2.Attributes.Add("onclick","Test();");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top