Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Creating dynamic textbox with "-" on the right (aspx image button)

this portion
RemoveA(this,' + value + ');
returns
RemoveA(this,' + value + ') 
in my debug mode.

Neccessary to push in the value, so as know which textbox is removed etc. Because of this, my website experience Page Validation issue.

 function GetDynamicFm(value) {
        var string1 = '<input name = "txtA' + value + '" id = "txtA' + value + '"  type="text" value = "" size="25" /> <asp:ImageButton ID="btnMinTextBox1" runat="server" ImageAlign="AbsMiddle" AutoPostBack="False" ImageUrl="../../img/minus_icon.png" onClientClick="RemoveA(this,' + value + ');return false;" ToolTip="Remove"/><input name = "hiddenAId' + value + '" id= "hiddenAId' + value + '" type="hidden" value=""/><input name = "hiddentxtA' + value + '" id="hiddentxtA' + value + '" type="hidden"/>';
}


What I have tried:

I tried a lot of ways. Sometime experienced "the server not well formed"
Posted
Updated 22-Jan-18 17:24pm

1 solution

There is no point of creating dynamic asp controls from javascript since the controls are processed from the server and rendered as html element in the browser page, The javascript is not aware of the asp prefix to the elements created. so replace the asp elements with the html element as
function GetDynamicFm(value) {
         var string1 = '<input name = "txtA' + value + '" id = "txtA' + value + '"  type="text" value = "" size="25" /> <img src="../../img/minus_icon.png" onclick="RemoveA(this,"' + value + '");return false;" title="Remove"/><input name = "hiddenAId' + value + '" id= "hiddenAId' + value + '" type="hidden" value=""/><input name = "hiddentxtA' + value + '" id="hiddentxtA' + value + '" type="hidden"/>';
         return string1;
     }

     var a = GetDynamicFm('-');


RemoveA(this,' + value + ') - this code will work only when a number is passed to the function, if there is any string then it will throw an error for invalid argument, so better pass it as string in all cases and use it accordingly

onclick="RemoveA(this,"' + value + '");
 
Share this answer
 
Comments
Member 13637757 23-Jan-18 5:21am    
Hi,

thanks, it works
Karthik_Mahalingam 23-Jan-18 5:24am    
welcome, if works please close this post formally by clicking "Accept answer".

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900