How to use Jquery on a Dynamical created Textbox [Resolved]

Posted by Vuyiswamb under jQuery on 9/27/2011 | Points: 10 | Views : 2482 | Status : [Member] [MVP] [Administrator] | Replies : 3
Good Day All

i am creating Textboxes at Runtime with something like this

Dim cnt As New TextBox

cnt.ID = "cont_" & x

If multiline Then
cnt.TextMode = TextBoxMode.MultiLine


End If


These are dynamically created fields. so what i want to do is to use this following JQuery on this textbox

$(document).ready(function()
{
$("#contentbox").keyup(function()
{
var box=$(this).val();
var main = box.length *100;
var value= (main / 145);
var count= 145 - box.length;

if(box.length <= 145)
{
$('#count').html(count);
$('#bar').animate({"width": value+'%',}, 1);
}
return false;
});

});

and what this function does it count the number of Characters that have been typed in a Textbox. so i am displaying the remaining characters. So that is working fine on my example because the Element is known at Early Binding. Now my question is what if the textbox is created dynamically ?

[code]
contentbox
[/code]

this is the name of the Textbox in my example.

hOW do we use a J Query in Dynamically created Textbox.


Thanks

Thank you for posting at Dotnetfunda
[Administrator]



Responses

Posted by: Vuyiswamb on: 9/28/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down

Resolved
Instead of ID get the textbox using Class.
i give the class of textbox for example let i give a class name 'contentbox'

cnt.cssClass = "contentbox"

and in javascript
$(".contentbox").keyup(function()


and it worked , thanks

Thank you for posting at Dotnetfunda
[Administrator]

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gausi on: 9/27/2011 [Member] Starter | Points: 25

Up
0
Down
if the textbox is created dynamically then u have to bind events to textbox at run time...
or execute script to bind events to textbox after creating textbox from code behind

Regards,

Gaurav Singh
(gausi)

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mdjack on: 9/28/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

Try this,

Panel pnlTextBox;
protected void Page_PreInit(object sender, EventArgs e)
{
//Create a Dynamic Panel
pnlTextBox = new Panel();
pnlTextBox.ID = "pnlTextBox";
pnlTextBox.BorderWidth = 1;
pnlTextBox.Width = 300;
this.form1.Controls.Add(pnlTextBox);

//Recreate Controls
RecreateControls("txtDynamic", "TextBox");
}

N. MOHAMED ZACKKARIAH

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response