?
Solved

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

Posted on 2004-08-14
8
Medium Priority
?
438 Views
Last Modified: 2013-11-25
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
Comment
Question by:nhorsley
[X]
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
8 Comments
 
LVL 9

Expert Comment

by:Joeisanerd
ID: 11802094
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
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11803046
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 15

Accepted Solution

by:
Thogek earned 1000 total points
ID: 11803088
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11803539
What did you use, "Disabled"  or  "readOnly"  ???
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11803540
please post your answer here..
0
 
LVL 1

Author Comment

by:nhorsley
ID: 11811454
I used: <input id="msgDate" Disabled="true" runat="server" /> on all the text boxes I wanted to disable.
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11812337
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

764 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