Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have create a textbox by simply clicking a button.
C#
TextBox txtGainMark = new TextBox();
txtGainMark.ID = count.ToString();
txtGainMark.Text = "GiveYourMark";
txtGainMark.TextChanged += new EventHandler(updateGivenMark);
placeholder.Controls.Add(txtGainMark);
Just all I need to get the new text of txtGainMark when someone rewrite it. But it's not work(updateGivenMark was not fired). I don't know what the problem is. Please somebody help me.
Posted
Updated 15-Sep-13 7:20am
v2
Comments
CHill60 15-Sep-13 13:27pm    
What does your declare of updateGivenMark look like. This fires up fine for me when I overtype "GiveYourMark"
sazzad37 15-Sep-13 13:33pm    
void updateGivenMark(object sender, EventArgs e)
{
TextBox t = (TextBox)sender;
lblDataOperation.Text = t.Text;
}
Here lblDataOperation is a label

1 solution

If you just need this operation you can use some of the events on clientside for textbox.

There is for example a onchange event for textbox on clientside. You can use it and after validation the text of your label will be changed.

Just add this line to your code and try it:
C#
txtGainMark.Attributes.Add("onchange", "javascript:document.getElementById('lblDataOperation').innerHTML = this.value;");


And remove the following code:
C#
txtGainMark.TextChanged += new EventHandler(updateGivenMark);


And here is a really good article how to send data from client to serverside in ASP .Net:
Send and receive JavaScript Array to Web Service Web Method using ASP .Net-AJAX[^]

I hope I could help you!
 
Share this answer
 
v4
Comments
sazzad37 16-Sep-13 2:00am    
Thank you very very much. It's working. @norbitrial
sazzad37 16-Sep-13 2:21am    
Can You help me little more, I need to call a function updateGivenMark when any one change the value of txtGainMark and get the changed value in a array variable.
norbitrial 16-Sep-13 3:45am    
I have improved my solution with a new link how to send and receive data from client to server.

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