Click here to Skip to main content
11,715,160 members (65,501 online)
Rate this: bad
good
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--->
    </div>
    <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("");
               document.getElementById("TextBoxContainer").appendChild(div);
               }
        function RemoveTextBox(div) {
            document.getElementById("TextBoxContainer").removeChild(div.parentNode);
        }
        function RecreateDynamicTextBox(){
            var values=eval('=Values');
            if(values!=null){
              var html="";
              for(var i=0;i<values.length;i++){>
                 html+="<div>" + GetDynamicTextBox*(values[i] + "<div>";
                 }
                 document.getElementById("TextBoxContainer").innerHTML=html;
                 }
             }
             window.onload=RecreateDynamicTextBoxes;
 
    </script>

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....

Thanks
Posted 15-Apr-13 21:25pm
v3
Rate this: bad
good
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

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

Solution 2

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

So by changing the onClick event to
onclick="Button2_Click"
might work for you.
  Permalink  
Comments
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 Sergey Alexandrovich Kryukov 495
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web01 | 2.8.150901.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