Unable to Get Text from Textbox Control

J

John Walker

Hi,
On the postback I am trying to get data from a TextBox control in a
Datagrid. This works fine except when the textbox has been disabled using
JavaScript. Here's the code to reference the control and get the text:

Dim txt As TextBox = CType(dg.Items(iMisc).FindControl("txtCustomer"),
TextBox)
Dim sCustomer As String = txt.Text

txt.Text will be blank if the textbox was disabled. Here's the javascript:

dml[sPrevboxid].disabled=true;

Are we not allowed to use JavaScript to disable datagrid textbox controls if
we want to reference the text on a postback?

Thanks, John
 
P

Phillip Williams

Hi John,

Disabling a control throws away its ViewState. Try instead

var txt= document.getElementById ("TextBoxName")
txt.readOnly=true;
txt.className="Disabled"

and in the Style section of your page:

<style>
..Disabled{background-color:gainsboro;}
</style>
 
J

John Walker

Phillip,
Thanks I'll try it.
John

Phillip Williams said:
Hi John,

Disabling a control throws away its ViewState. Try instead

var txt= document.getElementById ("TextBoxName")
txt.readOnly=true;
txt.className="Disabled"

and in the Style section of your page:

<style>
.Disabled{background-color:gainsboro;}
</style>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


John Walker said:
Hi,
On the postback I am trying to get data from a TextBox control in a
Datagrid. This works fine except when the textbox has been disabled using
JavaScript. Here's the code to reference the control and get the text:

Dim txt As TextBox = CType(dg.Items(iMisc).FindControl("txtCustomer"),
TextBox)
Dim sCustomer As String = txt.Text

txt.Text will be blank if the textbox was disabled. Here's the javascript:

dml[sPrevboxid].disabled=true;

Are we not allowed to use JavaScript to disable datagrid textbox controls if
we want to reference the text on a postback?

Thanks, John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top