Function to Make the Controls readonly.

Posted by Lakhangarg under JavaScript category on | Views : 2491
Pass the Control id as string array and this method will generate script to set the control read only at run time.

public static string MakeControlReadOnly(params string[] ControlIds)
System.Text.StringBuilder sb = new StringBuilder(400);
sb.Append("<script language='javascript'>\n");
for (int i = 0; i < ControlIds.Length; i++)
sb.Append("document.getElementById('" + ControlIds[i] + "').readOnly=true;");
return sb.ToString();

Comments or Responses

Posted by: Poster on: 9/4/2009 Level:Starter | Status: [Member]
Thanks Lakhan,

Can you please also write the code of how to call this function?

Posted by: Lakhangarg on: 9/7/2009 Level:Silver | Status: [Member] [Moderator]

Create an Array of ID's of control to whom you want to make read only then pass that array as argument.


This will return a script either call it directly from aspx page or call from .cs page and then add this script at runtime time either using resiterclientscript or any other appropriate method.

Login to post response