CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2006
    Location
    Hubli, India
    Posts
    70

    Unhappy ReadOnly TextBox in Update Panel

    I have a ReadOnly TextBox in an update panel along with several.

    I am loading some value using Ajax & Webservice to the TextBox so that it will be displayed to the user and not for changeing it .

    On Click of save button i am storing all the TextBox values along with this readonly textbox
    to database but the value is blank while reading in .VB page.

    What could be the problem , any HELP please

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: ReadOnly TextBox in Update Panel

    if you are only displaying data for a user to view and not be able to edit, you should use a label instead of a textbox.

  3. #3
    Join Date
    Aug 2006
    Location
    Hubli, India
    Posts
    70

    Re: ReadOnly TextBox in Update Panel

    No, the same problem with the label also. i have tried it


    What i am doing is , as the user selects the itemname, i am loading the rates of it with Javascript function calling webservice i.e. ajax , the rate displays, but when he clicks submit , i get the value of the label or textbox as it was in the begining of the page load

  4. #4
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: ReadOnly TextBox in Update Panel

    can you post your code?

  5. #5
    Join Date
    Aug 2006
    Location
    Hubli, India
    Posts
    70

    Re: ReadOnly TextBox in Update Panel

    Hey , yesterday i worked out and came to know that the problem is not only with the update panel, normally it happens that way

    i have done an example page to show the problem, i have taken 2 text box txtval1 and txtval2
    and summing them using javascript function, the answer is displayed in a label(lblsum) and read only textbox(txtsum). When i submit and try to read the sum it doesn't

    here is the default2.aspx code
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript" type="text/javascript">
            function calculate()
            {
                var v1 = document.getElementById('txtval1').value ;
                var v2 = document.getElementById('txtval2').value ;
                var sum = (v1*1) + (v2*1);
                document.getElementById('lblsum').innerHTML = sum ;
                document.getElementById('txtsum').value = sum ;
                
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Val1 :"></asp:Label>
            <asp:TextBox ID="txtval1" runat="server" onkeydown="calculate();"></asp:TextBox>
            <asp:Label ID="Label2" runat="server" Text="Val2 :"></asp:Label>
            <asp:TextBox ID="txtval2" runat="server" onkeydown="calculate();"></asp:TextBox>
            <br />
            <br />
            <asp:Label ID="Label3" runat="server" Text="Sum of 2 values calculated using javascript"></asp:Label><br />
            <br />
            <asp:Label ID="lblsum" runat="server" Text="0"></asp:Label>
            <asp:TextBox ID="txtsum" runat="server" ReadOnly="True">0</asp:TextBox><br />
            <br />
            &nbsp;<asp:Button ID="cmdSubmit" runat="server" Text="Submit the Sum" UseSubmitBehavior="False" /><br />
            <br />
            <asp:Label ID="Label4" runat="server" Text="The Submitted sum is :"></asp:Label>
            <br />
            <asp:Label ID="lblsubmittedsum1" runat="server" Text="Label"></asp:Label>
            <asp:Label ID="lblsubmittedsum2" runat="server" Text="Label"></asp:Label></div>
        </form>
    </body>
    </html>

    and here is the default2.aspx.vb code
    Code:
    Partial Class Default2
        Inherits System.Web.UI.Page
    
        Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
            'here it doesn't come
            lblsubmittedsum1.Text = lblsum.Text
            lblsubmittedsum2.Text = txtsum.Text
    
        End Sub
    End Class

  6. #6
    Join Date
    Aug 2006
    Location
    Hubli, India
    Posts
    70

    Re: ReadOnly TextBox in Update Panel

    somebody please help

  7. #7
    Join Date
    Sep 2009
    Posts
    7

    Re: ReadOnly TextBox in Update Panel

    Try not to make the textbox directly readonly by changing its properties.
    Try this one.It works.

    txtsum.Attributes.Add("readonly", "readonly")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured