Clear All Controls In asp net by javascript
Add This in your server side event
string myScript = String.Format("ClearAllControls();");ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Blank", myScript, true);
Javascript Function
function ClearAllControls()
{
var pnlMain = document.getElementById("updPanelMain");
var pnlMainControls = pnlMain.getElementsByTagName("input");
var pnlMainddlControls = pnlMain.getElementsByTagName("select");
var pnlMainControlstextarea = pnlMain.getElementsByTagName("textarea");
for (i = 0; i <=pnlMainControlstextarea.length-1 ; i++)
{
pnlMainControlstextarea[i].disabled = false;
pnlMainControlstextarea[i].innerHTML ="";
}
for (i = 0; i <=pnlMainControls.length-1 ; i++)
{
if (pnlMainControls[i].type == "text")
{
pnlMainControls[i].disabled = false;
pnlMainControls[i].value ="";
}
}
for (i = 0; i <=pnlMainddlControls.length-1 ; i++)
{
if(pnlMainddlControls[i].options[0]!=null || pnlMainddlControls[i].options[0]!=undefined)
{
pnlMainddlControls[i].disabled = false;
pnlMainddlControls[i].options[0].selected = true;
}
}
}
Add This in your server side event
string myScript = String.Format("ClearAllControls();");ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Blank", myScript, true);
Javascript Function
function ClearAllControls()
{
var pnlMain = document.getElementById("updPanelMain");
var pnlMainControls = pnlMain.getElementsByTagName("input");
var pnlMainddlControls = pnlMain.getElementsByTagName("select");
var pnlMainControlstextarea = pnlMain.getElementsByTagName("textarea");
for (i = 0; i <=pnlMainControlstextarea.length-1 ; i++)
{
pnlMainControlstextarea[i].disabled = false;
pnlMainControlstextarea[i].innerHTML ="";
}
for (i = 0; i <=pnlMainControls.length-1 ; i++)
{
if (pnlMainControls[i].type == "text")
{
pnlMainControls[i].disabled = false;
pnlMainControls[i].value ="";
}
}
for (i = 0; i <=pnlMainddlControls.length-1 ; i++)
{
if(pnlMainddlControls[i].options[0]!=null || pnlMainddlControls[i].options[0]!=undefined)
{
pnlMainddlControls[i].disabled = false;
pnlMainddlControls[i].options[0].selected = true;
}
}
}