TextBox.textChanged

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I create a new Textbox from code and i assign it a default value,
TextBox AddQtytxt = new TextBox();
AddQtytxt.Text = "test";

When the user change the text (to "testDone") i want to redirect the user to
a page and write the new value entered by user, i tried to use :
AddQtytxt.Attributes["onchange"] = "AddQtytxt_TextChanged('" +szPID+ "','"
+AddQtytxt.Text+ "');";
But i am getting the old value "test"

I am using Microsft Visual Studio .Net (C#) and i am writting the code in
page.cs
 
Hi Camelia,

If you create a control from code you have to recreate on each postback.
Then you do not use the Attributes collection, this is intended to be used
in the client, not in the server.

I have not very sure of what you want to do, the OnChange is a client event,
you have to write a javascript function ( as your code does) to do this.
It's this function the one responsible to check the value of the textbox
and do a redirect if the value match. if so you can modify the
document.location to the correct url, remember to include the value of the
textbox !.

just let me know if you need some code for this.

Cheers,
 
Well Thx for ur posting,
I will explain more what i have,
I am working on eshop project, Once i click a specific product item, it will
add it to the cart, and there the user have the right to change the quantity.
As you know i am doing a while loop to show all items added to my cart, but i
am not able to get the new quantity updated by the user:
while (objDataReader.Read()== true)
{
szPID = objDataReader.GetString("PID");
intQUANTITY = objDataReader.GetInt32("QUANTITY");
AddQtytxt.Attributes["onchange"] = "AddQtytxt_TextChanged('" +szPID+ "','"
+AddQtytxt.Text+ "');";
}

i KNOW THAT THE PROBLEM IS
TextBox AddQtytxt = new TextBox();
AddQtytxt.Text = intQUANTITY.ToString();
AddQtytxt.AutoPostBack = true;


Ignacio Machin ( .NET/ C# MVP ) said:
Hi Camelia,

If you create a control from code you have to recreate on each postback.
Then you do not use the Attributes collection, this is intended to be used
in the client, not in the server.

I have not very sure of what you want to do, the OnChange is a client event,
you have to write a javascript function ( as your code does) to do this.
It's this function the one responsible to check the value of the textbox
and do a redirect if the value match. if so you can modify the
document.location to the correct url, remember to include the value of the
textbox !.

just let me know if you need some code for this.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Camelia_Flower said:
I create a new Textbox from code and i assign it a default value,
TextBox AddQtytxt = new TextBox();
AddQtytxt.Text = "test";

When the user change the text (to "testDone") i want to redirect the user to
a page and write the new value entered by user, i tried to use :
AddQtytxt.Attributes["onchange"] = "AddQtytxt_TextChanged('" +szPID+ "','"
+AddQtytxt.Text+ "');";
But i am getting the old value "test"

I am using Microsft Visual Studio .Net (C#) and i am writting the code in
page.cs
 
Well Thx for ur posting,
I will explain more what i have,
I am working on eshop project, Once i click a specific product item, it will
add it to the cart, and there the user have the right to change the quantity.
As you know i am doing a while loop to show all items added to my cart, but i
am not able to get the new quantity updated by the user:
while (objDataReader.Read()== true)
{
szPID = objDataReader.GetString("PID");
intQUANTITY = objDataReader.GetInt32("QUANTITY");
TextBox AddQtytxt = new TextBox();
AddQtytxt.Text = intQUANTITY.ToString();
AddQtytxt.Attributes["onchange"] = "AddQtytxt_TextChanged('" +szPID+ "','"
+AddQtytxt.Text+ "');";
}

i KNOW THAT THE PROBLEM IS on Post back it is recreating the textbox from
scratch, but can you let me know a way to do what i need,
Thx in advance for ur support,
 
Back
Top