Hello Experts,
I am currently trying to use a code-behind created TextBox as the trigger for a TextBox_Changed event. I am able to get the TextBox created and even able to get EventHandler registered and assigned to the TextBox. However when I get to Debugging, I am receiving a browser error message in IE (I must develop for this browser - company guideline!). The error is 'TextBox_TextChanged' is undefined.
Here is my Code for creating the TextBox (actually a series of boxes, but it is the same for each one) -
if (sessVars[i].Keyvis == true)
{
TextBox txtBxNm = new TextBox();
txtBxNm.Width = 48;
txtBxNm.ID = "txtBoxNomPt" + rw + cl;
txtBxNm.AutoPostBack = true;
txtBxNm.Attributes.Add("OnChange", "TextBox_TextChanged");
txtBxNm.TextChanged += new EventHandler(TextBox_TextChanged);
this.NomFlds.Rows[rw].Cells[cl].Controls.Add(txtBxNm);
if (sessVars[i].Value != "" && sessVars[i] != null)
{
txtBxNm.Text = sessVars[i].Value.ToString();
}
this.NomFlds.Rows[rw].Cells[cl + 1].Text = sessVars[i].PosDesc.ToString();
}
The above Code appears inside my page_load / !=IsPostBack load of the page. Later on in the class code-behind I have the following method code for the event -
protected void TextBox_TextChanged(object sender, EventArgs e)
{
sql_val nom_p_des = new sql_val();
Control control = (Control)sender;
TextBox thisctrl = new TextBox();
control = (Control)thisctrl;
String ctrlName = control.ID;
int nmlen = ctrlName.Length;
int rmdr = nmlen - 11;
int posid = int.Parse(ctrlName.Substring(12, rmdr).ToString());
nom_p_des.Num_whr_flds = 0;
switch (posid)
{
case 00:
nom_p_des.Frm_table = "Position1";
nom_p_des.Keycall = true;
nom_p_des.Dtypefld = "str";
nom_p_des.Keypos = 1;
break;
case 01:
nom_p_des.Frm_table = "Position2";
nom_p_des.Keycall = true;
nom_p_des.Dtypefld = "str";
nom_p_des.Keypos = 2;
break;
….. It continues (but I don't make it this far!)
What I have tried:
I have tried changing the event (first I had the problem it wasn't even firing, then I changed to TextBoxChanged and it started firing - good). Now I am beginning to think there is some sort of rendering issue. When I look at Browser Debugger versions of other standard TextBox_Changed Events in other pages, they are render liked this inside the HTML -
onchange="javascript:setTimeout('__doPostBack(\'ctl00$TurbineWheel$TWExdDiam\',\'\')', 0)"
When I look at the Browser Debugger version of the Events for the code-behind generated Textboxes, they look like this after rendering in HTML -
onchange="TextBox_TextChanged;setTimeout('__doPostBack(\'
So it appears as if the conversion to JavaScript is missing. Not sure why. I would appreciate any / all help. Thanks.
---Ray