How to generate readonly attribute correctly?

H

Hamed

Hello

I have a DataGrid object in my ASP.NET page that has the following template
column. When I put the "readonly" attribute in the INPUT tag, it generates
readonly="".

<asp:TemplateColumn HeaderText="Kg Price" HeaderStyle-Width="5%">
<ItemTemplate><INPUT class="ep" id=kf readOnly value='<%#
DataBinder.Eval(Container, "DataItem.KgFee") %>' name=kf
runat="server"></ItemTemplate>
</asp:TemplateColumn>


As there is a lot of rows in the DataGrid, I want to remove three unneeded
attributes:
1- I want to remove the [=""] from the end of generated "readonly" attribute
in the page.
2- Is it possible to make CSS codes for ReadOnly attribute?
3- Is it possible to remove the type="text" part of the INPUT tag or move it
to the CSS code?

Bests
Hamed
 
H

Hamed

The page has some controls on the text and use it for some calculations. Is
it possible to get the value of some non INPUT tags such as the <td>my
integer value</td>?

I am using some JavaScript code like the following:

function kp()
{
var number=document.activeElement.id.substr(j.index,k);

var ctl = 'gd__ctl' + number + '_kf';
var myValue = Form1.all.namedItem(ctl);

//do some manipulation with myValue.
...

}




Eliyahu Goldin said:
2. No, not in standard CSS. But you can make a simple javascript that will
find all inputs that need to be readonly and set their readOnly property
to true.

3. Absolutely no.

Just wandering, may be you could use labels or literal content instead of
readonly textboxes?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Hamed said:
Hello

I have a DataGrid object in my ASP.NET page that has the following
template column. When I put the "readonly" attribute in the INPUT tag, it
generates readonly="".

<asp:TemplateColumn HeaderText="Kg Price" HeaderStyle-Width="5%">
<ItemTemplate><INPUT class="ep" id=kf readOnly value='<%#
DataBinder.Eval(Container, "DataItem.KgFee") %>' name=kf
runat="server"></ItemTemplate>
</asp:TemplateColumn>


As there is a lot of rows in the DataGrid, I want to remove three
unneeded attributes:
1- I want to remove the [=""] from the end of generated "readonly"
attribute in the page.
2- Is it possible to make CSS codes for ReadOnly attribute?
3- Is it possible to remove the type="text" part of the INPUT tag or move
it to the CSS code?

Bests
Hamed
 
E

Eliyahu Goldin

2. No, not in standard CSS. But you can make a simple javascript that will
find all inputs that need to be readonly and set their readOnly property to
true.

3. Absolutely no.

Just wandering, may be you could use labels or literal content instead of
readonly textboxes?
 
E

Eliyahu Goldin

Yes, instead of getting a reference to the textbox, you can get a reference
to the <td> and use it's innerText property. In this case you might not need
an item template in the first case. Just make a BoundColumn bound to KgFee.
The values will go straight inside the <td>s. The grid will render as a
table and you should be able to loop through the rows and cells collections
in javascript. Or you can consider replacing the grid with a repeater with
item template something like
<tr>
<td class="ep" id=kf name=kf >'<%# DataBinder.Eval(Container,
"DataItem.KgFee") %>'</td>
</tr>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Hamed said:
The page has some controls on the text and use it for some calculations.
Is it possible to get the value of some non INPUT tags such as the <td>my
integer value</td>?

I am using some JavaScript code like the following:

function kp()
{
var number=document.activeElement.id.substr(j.index,k);

var ctl = 'gd__ctl' + number + '_kf';
var myValue = Form1.all.namedItem(ctl);

//do some manipulation with myValue.
...

}




Eliyahu Goldin said:
2. No, not in standard CSS. But you can make a simple javascript that
will find all inputs that need to be readonly and set their readOnly
property to true.

3. Absolutely no.

Just wandering, may be you could use labels or literal content instead of
readonly textboxes?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Hamed said:
Hello

I have a DataGrid object in my ASP.NET page that has the following
template column. When I put the "readonly" attribute in the INPUT tag,
it generates readonly="".

<asp:TemplateColumn HeaderText="Kg Price" HeaderStyle-Width="5%">
<ItemTemplate><INPUT class="ep" id=kf readOnly value='<%#
DataBinder.Eval(Container, "DataItem.KgFee") %>' name=kf
runat="server"></ItemTemplate>
</asp:TemplateColumn>


As there is a lot of rows in the DataGrid, I want to remove three
unneeded attributes:
1- I want to remove the [=""] from the end of generated "readonly"
attribute in the page.
2- Is it possible to make CSS codes for ReadOnly attribute?
3- Is it possible to remove the type="text" part of the INPUT tag or
move it to the CSS code?

Bests
Hamed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top