Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


When I use readonly my insert is throwing a error

Posted on 2008-10-27
Medium Priority
Last Modified: 2012-05-05
whenever I add readonly to my textBox I get a error when I try to do a insert. Any ideas?

Here is my javscript
function priceTextBox_TextChanged()

                A = document.getElementById("<%=qtyTextBox.ClientID%>").value
                B = document.getElementById("<%=priceTextBox.ClientID%>").value
                C = eval(A * B)
                var num = eval(C);
                var price = eval(B);
                var result = num.toFixed(2);
                var resultprice = price.toFixed(2);
                document.getElementById("<%=priceTextBox.ClientID%>").value = resultprice
                document.getElementById("<%=extendedTextBox.ClientID%>").value = result        
                 return true;

function qtyTextBox_move()

function descriptionItemTextBox_move()


//A = document.form1.qtyTextBox.text
//B = document.form1.priceBox.text
//C = (A + B)
//document.form1.extendedTextBox.text = eval(A*B)



 <asp:TextBox ID="extendedTextBox" style="text-align: right;"  runat="server" Width="88px"
                    ToolTip="Total for all of this line item"   Onmouseout="priceTextBox_TextChanged()"  TextMode="MultiLine"


Dim cnn As New SqlConnection("myconnectionstring")
        Dim InsertCommand As SqlCommand = New SqlCommand()
        InsertCommand.Connection = cnn
        Dim sqlInsert As String
        sqlInsert = "INSERT INTO imtbl_templineitem (sessionID, description, unitPrice, extendedAmount, vehicleNumber, qty) VALUES     ("
        sqlInsert += "'" + Session("user") + "',"
        sqlInsert += "'" + descriptionItemTextBox.Text + "',"
        sqlInsert += priceTextBox.Text + ","
        sqlInsert += extendedTextBox.Text + ","
        sqlInsert += VehicleListBox.SelectedValue + ","
        sqlInsert += qtyTextBox.Text + ")"
        InsertCommand.CommandText = sqlInsert
        loadLabel.Text = "adf"
        descriptionItemTextBox.Text = ""
        qtyTextBox.Text = "0"
        VehicleListBox.SelectedValue = "0"
        extendedTextBox.Text = "0"

Question by:soccerman777
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 10

Accepted Solution

jinn_hnnl earned 2000 total points
ID: 22815537
I can get, When a control is set to ReadOnly, or Enable = false, it wont be store in ViewState, when the page is posted back, server doesnt retains the control value in the viewstate.

I have this problem when you want to update objectdatasource of the gridview, I want to protect some field which are not DataKey. But I guess they have the same logic.

THe work around is, you can set a hidden field for the corresponding textbox and always set the value of this hidden field as the textbox one when you change (change both). So both are readonly to user

This can be a work around


Author Comment

ID: 22815669
Let me ask you this I trid to caculate the value on the next page like this

Dim newTotal As Double = priceTextBox.Text * qtyTextBox.Text

So I am creating a value Dimed as Double but when I try to insert iusing the insert statment above it throws a error saying  "conversion from string "insert into imtbl_templineitem ("to type 'Double' is not valid

Do you see what the problem with the conversion is. By the way if I put newTotal var that I dimmed above into a text box it outputs the correct amount

Author Closing Comment

ID: 31510474
I actually just set the textfield to read only and recaculated the amount on the post back and got the same amount. I also had to Dim the new var as String for some reason(even through my data type is decimal(8,2) ). But your answer was a just as good.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 10

Expert Comment

ID: 22817684
You have to cast them specifically each of the value you got out of the these textbox

    Dim newTotal As Double = Double.Parse(priceTextBox.Text) * Double.Parse(qtyTextBox.Text)
Catch ...
'      ... throw exception
End Try

You have to handle exception here too incase the input is not in double format which can cause the page to crash. Take care of the server culture dependent (such as dot. and comma) to have accurate account ^^

Hope this helps



Author Comment

ID: 22821285
I tried
Dim newTotal As Double = Double.Parse(priceTextBox.Text) * Double.Parse(qtyTextBox.Text)
 but it gave me the same error. For some reason it is forcing me to cast it as string. I realize even though I sent it to my textbox as a decimat that a textbox is going to send it as a string but I am not sure why it wil not let me convert it.
LVL 10

Expert Comment

ID: 22821471
That's odd. Can you try this:
Dim newTotal As Double
newTotal  = CDbl(priceTextBox.Text) * CDbl(qtyTextBox.Text)

You can also try CDec or Double.TryParse

Remember to put these casting inside a Try Catch to handle exception.

Have you debug to see what's the value of the priceTextBox.Text?


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question