Click here to Skip to main content
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 22: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 Peter Leow 268
1 Maciej Los 220
2 Kornfeld Eliyahu Peter 220
3 Sergey Alexandrovich Kryukov 202
4 ProgramFOX 185
0 Kornfeld Eliyahu Peter 240
1 Peter Leow 230
2 Maciej Los 220
3 Sergey Alexandrovich Kryukov 207
4 ProgramFOX 205

Advertise | Privacy | Mobile
Web03 | 2.8.150301.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