Click here to Skip to main content
15,887,596 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.Attributes.Add("onchange", "javascript:document.getElementById('lblDataOperation').innerHTML = this.value;");
placeholder.Controls.Add(txtGainMark);
when I change the txtGainMark's text, the result shown into a label "lblDataOperation", but I want to get the changed value into a string variable and call a C# function with that value as a parameter.
Posted
Comments
Harshil_Raval 16-Sep-13 3:06am    
Hi, you want to call server side event, when textbox value change? or after changing value on some button click event you want to get textbox value?

C#
protected void Page_Load(object sender, EventArgs e)
   {
       TextBox textBox = new TextBox();
       textBox.TextChanged += new EventHandler(textBox_TextChanged);
   }

   protected void textBox_TextChanged(object sender, EventArgs e)
   {
       // Your code here
   }



Hope this will help.
 
Share this answer
 
Comments
sazzad37 16-Sep-13 2:54am    
I have try this, but it's not work.(I am not using Page_Load to create dynamic textbox)
Gitanjali Singh 16-Sep-13 3:25am    
http://www.codeproject.com/Questions/653847/How-to-use-EventHandler-for-dynamic-textbox

try this
Before adding Textbox to placeholder, just bind TextChanged event to it.

C#
{

    //... same previous code

    txtGainMark.TextChanged += new EventHandler(txtGainMark_TextChanged);
    placeholder.Controls.Add(txtGainMark);
}
protected void txtGainMark_TextChanged(object sender, EventArgs e)
{
    // Do your work here
}


Ask, if any problem :)
 
Share this answer
 
v2
Comments
sazzad37 16-Sep-13 3:13am    
I have try this, but txtGainMark_TextChanged was not fired when I change anything in my textbox.
Anand Kumar Prajapati 16-Sep-13 3:38am    
Add this also, before adding it to placeholder -
txtGainMark.AutoPostBack=true;
JoCodes 16-Sep-13 3:25am    
Tried an autopostback property added to the dynamic textbox for the text change event to be fired??
Anand Kumar Prajapati 16-Sep-13 3:38am    
Thumbs Up!
sazzad37 16-Sep-13 5:08am    
When I set autopostback property true then the textbox txtGainMark will divisible. But I need it visible.
Yes please check with autopostback property. You are not submitting the page on text chnage thats why unable to submit the page.
 
Share this answer
 
Comments
sazzad37 16-Sep-13 5:07am    
When I set autopostback property true then the textbox txtGainMark will divisible. But I need it visible.
sazzad37 16-Sep-13 5:33am    
I have manage. Thank you for your reply

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