Click here to Skip to main content
11,806,026 members (62,230 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
hi ,

i am unable to call a javascript function on a button click .
i am getting the following error

> Microsoft JScript runtime error: 'AddTextBox' is undefined

Please find the code below:

Source :
<asp:Button ID="Button2"  runat="server"   Text="Add License"
        onClientClick="AddTextBox()" onclick="Button2_Click1" />
       <div id="TextBoxContainer">
       <!----Textboxes will be added here--->
    <script type="text/javascript">
        function GetDynamicTextBox(value) {
            return '<input name = "DynamicTextBox" type="text" value="' + value + '"/>' + '<input type="button" value="Remove" onclick="RemoveTextBox(this)"/>'
         function AddTextBox(){
               var div = document.createElement('DIV');
               div.innerHTML = GetDynamicTextBox("");
        function RemoveTextBox(div) {
        function RecreateDynamicTextBox(){
            var values=eval('=Values');
              var html="";
              for(var i=0;i<values.length;i++){>
                 html+="<div>" + GetDynamicTextBox*(values[i] + "<div>";

Code of button click:
protected void Button2_Click(object sender, EventArgs e)
    string[] textboxvalues = Request.Form.GetValues("DynamicTextBox");
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    this.Values = serializer.Serialize(textboxvalues);
Please help and thanks in advance....

Posted 15-Apr-13 21:25pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It's a syntacticle error. Since you missed a close braces ')' here:
html+="<div>" + GetDynamicTextBox*(values[i] + "<div>";
Replace the line with following:
html+="<div>" + GetDynamicTextBox*(values[i] + "<div>");
And also onload you are calling window.onload=RecreateDynamicTextBoxes; whereas your function name is RecreateDynamicTextBox

Sophia Ranjani Elango at 16-Apr-13 8:29am
Thank u so much.
_Amy at 16-Apr-13 8:30am
Welcome. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I think, in onClick event you have called
but there is no definition for the same.

So by changing the onClick event to
might work for you.
Sophia Ranjani Elango at 16-Apr-13 8:46am
thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Richard Deeming 225
1 OriginalGriff 215
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 120
4 ppolymorphe 115
0 OriginalGriff 3,330
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,905
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100