Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

asp.net vb: make asp.net text box value inactive

I populate text boxes from an sql server query so that the user can update them.  But I want some of the text boxes to be visible but not editable.  I've tried changing them to labels but my code breaks and it's not worth going in that direction.  I just  want to make the values inactive.

This is the code I'm using for page in question.  Please show me how to change it to make just one text box inactive.  I can figure out the rest.

<%@ Page Language="c#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">


    SqlConnection myConn = new SqlConnection ("server=(local);database=BCA;trusted_connection=true");
    SqlCommand myCmd = new SqlCommand ( );
    string id;
      protected string strUser;

        
    protected void Page_Load ( object src, EventArgs e ) {

Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60)) + @"; URL=default.aspx");

       
 myCmd.Connection = myConn;
        id = Request.QueryString [ "id" ] ;
        if ( !IsPostBack ) {
           if ( id == null ) {
              bindGrid ( );
              loadPanel.Visible = true;
              editPanel.Visible = false;
              postPanel.Visible = false;
           } else {
              getMessage ( Request.QueryString [ "id" ] );
              loadPanel.Visible = false;
              editPanel.Visible = true;
              postPanel.Visible = false;
           }
        } else {
           loadPanel.Visible = false;
           editPanel.Visible = false;
           postPanel.Visible = true;
        }
    }
   
    public void bindGrid ( )
{
     SqlParameter myParam = new SqlParameter("@IncidentStatus", SqlDbType.NVarChar, 50);
     myParam.Value = "Open";
     myCmd.Parameters.Add(myParam);
     myCmd.CommandText = "SELECT * FROM BCAIncident WHERE IncidentStatus = @IncidentStatus";
 
      myConn.Open ( );
      myGrid.DataSource = myCmd.ExecuteReader ( CommandBehavior.CloseConnection );
      myGrid.DataBind ( );
}

   
    public void getMessage ( String id ) {
        SqlDataAdapter myAdapter = new SqlDataAdapter (
           "select * from BCAIncident where IncidentID=" + id, myConn );
        DataTable msgDetails = new DataTable ( );
        myAdapter.Fill ( msgDetails );
        DataRowView myRow = msgDetails.DefaultView [ 0 ] ;
   
        msgID.Value = myRow [ "IncidentID" ].ToString ( );
        msgFrom.Value = myRow [ "IncidentAuthorID" ].ToString ( );
        msgEmail.Value = myRow [ "IncidentEmail" ].ToString ( );
      msgDate.Value = myRow [ "IncidentDate" ].ToString ( );
        msgDesc.Value = myRow [ "IncidentDesc" ].ToString ( );
        msgShrtDesc.Value = myRow [ "IncidentShrtDesc" ].ToString ( );
        msgStatus.Value = myRow [ "IncidentStatus" ].ToString ( );
        msgAction.Value = myRow [ "IncidentAction" ].ToString ( );
        msgCompleted.Value = myRow [ "IncidentCompleted" ].ToString ( );
        msgIncName.Value = myRow [ "IncidentName" ].ToString ( );
        msgIncOwner.Value = myRow [ "IncidentOwner" ].ToString ( );
      msgCompany.Value = myRow [ "Company" ].ToString ( );
        editPanel.DataBind ( );
    }
   
    public void updateMessage ( object src, EventArgs e ) {
        if ( Page.IsValid ) {
           myCmd.CommandText = "UPDATE BCAIncident SET IncidentAuthorID=@From, IncidentEmail=@Mail, IncidentDesc=@Desc, IncidentShrtDesc=@ShrtDesc, IncidentStatus=@Status, IncidentAction=@Action, IncidentCompleted=@Completed, IncidentName=@IncName, IncidentOwner=@IncOwner, Company=@Company where IncidentID=" + id;
   
           myCmd.Parameters.Add ( "@From", SqlDbType.NVarChar ).Value = msgFrom.Value;
           myCmd.Parameters.Add ( "@Mail", SqlDbType.NVarChar ).Value = msgEmail.Value;
           myCmd.Parameters.Add ( "@Desc", SqlDbType.NVarChar ).Value = msgDesc.Value;
         myCmd.Parameters.Add ( "@Date", SqlDbType.NVarChar ).Value = msgDate.Value;
           myCmd.Parameters.Add ( "@ShrtDesc", SqlDbType.VarChar ).Value = msgShrtDesc.Value;
           myCmd.Parameters.Add ( "@Status", SqlDbType.NVarChar ).Value = msgStatus.Value;
           myCmd.Parameters.Add ( "@Action", SqlDbType.VarChar ).Value = msgAction.Value;
           myCmd.Parameters.Add ( "@Completed", SqlDbType.VarChar ).Value = msgCompleted.Value;
           myCmd.Parameters.Add ( "@IncName", SqlDbType.NVarChar ).Value = msgIncName.Value;
           myCmd.Parameters.Add ( "@IncOwner", SqlDbType.NVarChar ).Value = msgIncOwner.Value;
         myCmd.Parameters.Add ( "@Company", SqlDbType.NVarChar ).Value = msgCompany.Value;
           myConn.Open ( );
           myCmd.ExecuteNonQuery ( );
           myConn.Close ( );
        }
        bindPostPanel ( id );
    }
   
    public void bindPostPanel ( String id ) {
        myCmd.CommandText = "SELECT * FROM BCAIncident WHERE IncidentID='" + id + "'";
        myConn.Open ( );
        listDetails.DataSource = myCmd.ExecuteReader ( CommandBehavior.SingleRow );
        listDetails.DataBind ( );
        myConn.Dispose ( );
    }

</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/TR/REC-html40" xmlns:v= "urn:schemas-microsoft-com:vml" xmlns:o= "urn:schemas-microsoft-com:office:office">
<head><script>
          if (navigator.appName=='Netscape') document.captureEvents(Event.MOUSEMOVE);
if (navigator.appName=='Netscape') document.captureEvents(Event.KEYPRESS);
TId = ""; // make var global in scope

function resetTimer() {
   clearTimeout(TId);  //resets the timer once the mouse moves
   TId = setTimeout('location=\'/memberarea/login.aspx?ReturnUrl=%2fmemberarea%2fdefault.aspx\'',1500000);
}

document.onkeypress=resetTimer;
document.onmousemove=resetTimer;
          </script>
    <title>BCA Update</title> <style type="text/css">#editPanel {
      BORDER-RIGHT: thin outset; PADDING-RIGHT: 10px; BORDER-TOP: thin outset; PADDING-LEFT: 10px; BACKGROUND: khaki; PADDING-BOTTOM: 10px; BORDER-LEFT: thin outset; WIDTH: 90%; PADDING-TOP: 10px; BORDER-BOTTOM: thin outset
}
#posted {
      BORDER-RIGHT: thin inset; BORDER-TOP: thin inset; BACKGROUND: #b3c4de; BORDER-LEFT: thin inset; BORDER-BOTTOM: thin inset
}
</style>
</head>
<body style="TEXT-ALIGN: center" vlink="#336699" alink="#336699" link="#336699" bgcolor="#eeeeee" leftmargin="0" topmargin="0">

This is the EDIT PANEL

    <center>&nbsp;<asp:panel id="editPanel" runat="server" ForeColor="#33679B" Font-Names="Verdana" BackColor="AliceBlue" Width="530px" Height="611px"><h5>To save changes to the database, press Update. </h5>
<form runat="server"><input id="msgID" type="hidden" runat="server" /><table cellspacing="1" cellpadding="3" width="85%" border="0"><colgroup><col align="right" width="40%" /><col width="60%" /><tbody><tr><td bordercolor="red" align="left" bgcolor="white"><font color="#495e76">Incident Date:</font></td><td><input id="msgDate" runat="server" /></td></tr>  <tr><td bordercolor="red" align="left" bgcolor="white"><font color="#495e76">UserName:</font></td><td> <input id="msgFrom" runat="server" /><asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="msgFrom" errormessage="UserName cannot be blank. " display="none"></asp:requiredfieldvalidator> </td></tr><tr><td bordercolor="red" align="left" bgcolor="white"> <font color="#495e76">Company:</font></td><td><input id="msgCompany" runat="server" />
                                                                                                                                                                            <asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" controltovalidate="msgFrom" errormessage="Company cannot be blank. " display="none"></asp:requiredfieldvalidator>
   </td>  </tr>
     <tr>
    <td bgcolor="white"> <p align="left">   <font color="#3a6178">User's Email Address:</font> </p> </td> <td><p align="left"><input id="msgEmail" runat="server" />                                                                                                 <asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server" controltovalidate="msgEmail" errormessage="Please enter a valid e-mail address. " display="none" validationexpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"></asp:regularexpressionvalidator>  </p></td> </tr><tr> <td bgcolor="white"><p align="left"><font color="#407079">Short Description:</font>  </p> </td><td><p align="left"><input id="msgShrtDesc" style="WIDTH: 286px; HEIGHT: 22px" size="40" runat="server" />  </p> </td> </tr><tr>  <td><p align="left"><font color="#408080">Incident Description:</font>   </p> </td><td>   <p align="left"></p><textarea id="msgDesc" rows="5" cols="35" runat="server"></textarea></td> </tr> <tr><td bgcolor="white"> <p align="left"><font color="#407079">Incident Status:</font> </p></td> <td> <p align="left"><input id="msgStatus" style="WIDTH: 294px; HEIGHT: 22px" size="40" runat="server" /> </p></td> </tr> <tr>  <td bgcolor="white"><p align="left"><font color="#407079">Incident Action Taken:</font>  </p> </td> <td><p align="left"><input id="msgAction" style="WIDTH: 286px; HEIGHT: 22px" size="40" runat="server" /></p></td></tr>
  <tr>
   <td bgcolor="white"> <p align="left">
                                                                                                                                                                                <font color="#407079">Incident Completed:</font> </p></td><td><p align="left"> <input id="msgCompleted" style="WIDTH: 286px; HEIGHT: 22px" size="40" runat="server" /></p> </td></tr> <tr><td bgcolor="white"><p align="left"><font color="#407079">Incident Name:</font> </p></td><td>   <p align="left"><input id="msgIncName" style="WIDTH: 286px; HEIGHT: 22px" size="40" runat="server" /></p></td></tr> <tr><td bgcolor="white"> <p align="left"><font color="#407079">Incident Owner:</font>  </p> </td> <td><input id="msgIncOwner" style="WIDTH: 286px; HEIGHT: 22px" size="40" runat="server" /></td></tr><tr>  <td bgcolor="white"><font color="#408080">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></td>
  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td></tr> </tbody></colgroup>
  </table> <p><input type="submit" value="Update" runat="server" onserverclick="updateMessage" /><input onclick="self.location.replace ( 'updateAdmin.aspx' ) " type="reset" value="Cancel" /> </p><asp:validationsummary id="ValidationSummary1" runat="server" displaymode="SingleParagraph" showmessagebox="true" showsummary="false"></asp:validationsummary> </form></asp:panel>
0
nhorsley
Asked:
nhorsley
1 Solution
 
JoeisanerdCommented:
In internet explorer you make textboxes disabled by setting changing the enabled state to false.

Are these your textboxes?
  msgID.Value = myRow [ "IncidentID" ].ToString ( );
        msgFrom.Value = myRow [ "IncidentAuthorID" ].ToString ( );
        msgEmail.Value = myRow [ "IncidentEmail" ].ToString ( );
     msgDate.Value = myRow [ "IncidentDate" ].ToString ( );
        msgDesc.Value = myRow [ "IncidentDesc" ].ToString ( );
        msgShrtDesc.Value = myRow [ "IncidentShrtDesc" ].ToString ( );
        msgStatus.Value = myRow [ "IncidentStatus" ].ToString ( );
        msgAction.Value = myRow [ "IncidentAction" ].ToString ( );
        msgCompleted.Value = myRow [ "IncidentCompleted" ].ToString ( );
        msgIncName.Value = myRow [ "IncidentName" ].ToString ( );

if you changed them to labels and changed to msgID.Text that should work.
0
 
DotNetLover_BaanCommented:
Ok, looks like you are using HTML "Input" boxes, not ASP TextBoxes. Well, then you can set the "Disabled" property to TRUE.
msgFrom.Disabled = True
...

-Baan
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
ThogekCommented:
0
 
DotNetLover_BaanCommented:
What did you use, "Disabled"  or  "readOnly"  ???
0
 
DotNetLover_BaanCommented:
please post your answer here..
0
 
nhorsleyAuthor Commented:
I used: <input id="msgDate" Disabled="true" runat="server" /> on all the text boxes I wanted to disable.
0
 
DotNetLover_BaanCommented:
Good... but you know what...  that's exactly what I told you to do before anyone else...  So, I guess I was supposed to get the points. !!!!
Don't you think so ??
-Baan
0

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now