Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
protected void Page_Load(object sender, EventArgs e)
{
    BtnPrint.Attributes.Add("onclick", "javascript:"
      + BtnPrint.ClientID + ".disabled=true;"
      + Page.ClientScript.GetPostBackEventReference(BtnPrint, null));

    //Renable the button after 10 seconds
    string Script = @"<script language ='javascript'>
       window.setTimeout('enable()', 10000)
       function enable()
{
   document.getElementById('$BTNAME').disabled = 0;
}
      </script>";

    Script = Script.Replace("$BTNAME", BtnPrint.ClientID);
    Page.ClientScript.RegisterStartupScript(GetType(), "script", Script);
}


above code is for Renable the button after 10 seconds
now i want is first take a variable x=10000;
then instead of passing 10000 i pass x variable to setTimeout('enable()',x)
this how can i do?
Posted

1 solution

Well pretty simple, following your example:

C#
protected void Page_Load(object sender, EventArgs e)
{
    int x = 1000;
    BtnPrint.Attributes.Add("onclick", "javascript:"
      + BtnPrint.ClientID + ".disabled=true;"
      + Page.ClientScript.GetPostBackEventReference(BtnPrint, null));

    //Renable the button after x seconds
    string Script = @"<script language ="'javascript'">
       window.setTimeout('enable()', " + x.ToString() + ")
       function enable()
{
   document.getElementById('$BTNAME').disabled = 0;
}
      </script>";

    Script = Script.Replace("$BTNAME", BtnPrint.ClientID);
    Page.ClientScript.RegisterStartupScript(GetType(), "script", Script);
}


Cheers
 
Share this answer
 
Comments
Sandeep Mewara 3-May-12 4:54am    
5'ed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900