Generate Readonly Textbox based on Database Row ID

Tips submitted by ASP.NET Maker users

Generate Readonly Textbox based on Database Row ID

Postby xgis » Sun Aug 04, 2013 9:25 am

Fields may need to be set into ReadOnly mode if they do not need to be changed.
In this example I have related Child tables that require two primary keys to be transferred from the Master/Parent table.
The Field Textbox control that is being made ReadOnly is a GUID field, but could be any field that you do not want changed.

This example uses both razor syntax (@) and C# (;) to achieve the readonly status.
This script is located in the "Table-Specific - Common - Row_Rendered" Event.
It is important to remember that c# is case dependant.

The code does 3 things;
1. Checks to see if the RowID is not null by getting the RowID
2. Filters the Edit Value based on the RowID
3. Sets the field textbox to ReadOnly

// Row Rendered event
public void Row_Rendered() {
if (ew_Session["SiteID"] != null)
{
GlobalID.EditValue = ew_ExecuteScalar("@SELECT GlobalID FROM DMPDB.DMP_Sites WHERE SiteID = " + ew_Session["@SiteID"]);
}
GlobalID.ReadOnly = true;
}
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm

Re: Generate Readonly Textbox based on Database Row ID

Postby xgis » Tue Aug 06, 2013 3:14 pm

The SQL code sample above may have some issues or do nothing at all.
Please note to set a field to read only just use the server side code in the events that it is required;

<field>.ReadOnly = true;
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm


Return to User Submited Tips (ASP.NET Maker)