To clear textboxes in the content page
-
hi... i am having a contentpage which has many textboxes.Pls let me know the code(in c#)to clear textboxes at a button click. SunithaNallana
-
hi... i am having a contentpage which has many textboxes.Pls let me know the code(in c#)to clear textboxes at a button click. SunithaNallana
SunithaNallana wrote:
to clear textboxes at a button click.
Clearing textbox value ?
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
SunithaNallana wrote:
to clear textboxes at a button click.
Clearing textbox value ?
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
yes to clear textboxes values SunithaNallana
-
hi... i am having a contentpage which has many textboxes.Pls let me know the code(in c#)to clear textboxes at a button click. SunithaNallana
Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:
-
Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:
Prateek G wrote:
ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; }
No need to loop 2 Times. foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { Textbox t = (Textbox)c; t.Text = ""; } }
Thanks, Sun Rays
-
yes to clear textboxes values SunithaNallana
Content place holder will have Control collection property. Iterate through each item and check if it is TextBox. If yes clear the text.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:
Prateek G wrote:
foreach(Control c in Page.Form.Controls)
This will clear all textbox controls in page. I think question is how to clear the textbox in content place holder.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
hi... i am having a contentpage which has many textboxes.Pls let me know the code(in c#)to clear textboxes at a button click. SunithaNallana
Try this and call this function on the server side. < script > function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } } < /script > Let me know whether you got the solution.:) God is always with you.
-
Try this and call this function on the server side. < script > function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } } < /script > Let me know whether you got the solution.:) God is always with you.
Saranya Devi wrote:
function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } }
This will clear all textboxes, not in the controls in content page
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Saranya Devi wrote:
function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } }
This will clear all textboxes, not in the controls in content page
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
thank u all:rose: i cleared my doubt. i have done it this way... 1.in the master page i put a property block in which i wrote public ContentPlaceHolder CPH { get{return ContentPlaceHolderid;} } 2.i made the content page strongly typed ie.. 3.in button click function foreach(control c in Master.CPH.Controls) { if(c.getType().Name == "TextBox") { (c as TextBox).Text =""; } } SunithaNallana
-
Content place holder will have Control collection property. Iterate through each item and check if it is TextBox. If yes clear the text.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
thank u all:rose: i cleared my doubt. i have done it this way... 1.in the master page i put a property block in which i wrote public ContentPlaceHolder CPH { get{return ContentPlaceHolderid;} } 2.i made the content page strongly typed ie.. 3.in button click function foreach(control c in Master.CPH.Controls) { if(c.getType().Name == "TextBox") { (c as TextBox).Text =""; } } SunithaNallana
-
Prateek G wrote:
foreach(Control c in Page.Form.Controls)
This will clear all textbox controls in page. I think question is how to clear the textbox in content place holder.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
thank u all:rose: i cleared my doubt. i have done it this way... 1.in the master page i put a property block in which i wrote public ContentPlaceHolder CPH { get{return ContentPlaceHolderid;} } 2.i made the content page strongly typed ie.. 3.in button click function foreach(control c in Master.CPH.Controls) { if(c.getType().Name == "TextBox") { (c as TextBox).Text =""; } } SunithaNallana
-
Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:
thank u Prateek.G for wishing me on my birthday.:rose: SunithaNallana