Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-14
8
Medium Priority
?
440 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
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!

 
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

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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