Set Multiple Textboxes inside the Panel to Readonly

Bugwee
Posted by Bugwee under ASP.NET category on | Points: 40 | Views : 6623
the panel on aspx page
 <asp:Panel ID="pnlBranch" runat="server">
<%-- your multiple textbox inside --%>
</asp:Panel>


to set multiple textbox to readonly
Protected Sub SetReadOnlyTrue()
For Each ctrl As Control In pnlBranch.Controls
If TypeOf ctrl Is TextBox Then
CType(ctrl, TextBox).ReadOnly = True
End If
Next
End Sub

Comments or Responses

Posted by: Akiii on: 5/24/2011 Level:Bronze | Status: [Member] | Points: 10
Hi bugwee.....

Can you convert this code in C#.....please?

Thanks and Regards
Akiii
Posted by: Bugwee on: 5/25/2011 Level:Starter | Status: [Member] | Points: 10
hello Akiii,

Here's the code using c#.. Hope this may help..

protected void SetReadOnlyTrue()

{

foreach (Control ctrl in pnlBranch.Controls)
{

if (ctrl is TextBox)
{
((TextBox)ctrl).ReadOnly = true;

}

}

}


Regards,
Bugwee
Posted by: Akiii on: 5/25/2011 Level:Bronze | Status: [Member] | Points: 10
Hi bugwee.....

Thanks friend........your code is working absolutely fine.....

But can you tell me on what occasions a text-box should be made read-only......?
Text boxes are used for writing texts ......right ?

Thanks and Regards
Akiii
Posted by: Bugwee on: 5/25/2011 Level:Starter | Status: [Member] | Points: 10
Hello Akiii,

Mostly my projects are e.g. data entries or POS. Therefore, i have to set it to read-only when the users just want to view their previous entries.

Regards,
Bugwee
Posted by: Akiii on: 5/25/2011 Level:Bronze | Status: [Member] | Points: 10
hi bugwee.....

Okay, but in what other scenarios we may use text box as readonly...?

Regards
Akiii
Posted by: Bugwee on: 5/25/2011 Level:Starter | Status: [Member] | Points: 10
Hello Akiii,

We may set the textbox to readonly to prevent a malicious user from changing a Text value that is read-only.

Regards,
Bugwee
Posted by: Akiii on: 5/25/2011 Level:Bronze | Status: [Member] | Points: 10
hi bugwee....

okay.....thanks for the info.....and the code....
keep posting.....

Regards
Akiii

Login to post response