Click here to Skip to main content
15,917,473 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Problem with page's button click event handler Pin
Not Active9-Jan-07 17:24
mentorNot Active9-Jan-07 17:24 
GeneralRe: Problem with page's button click event handler Pin
Tina P9-Jan-07 18:10
Tina P9-Jan-07 18:10 
GeneralRe: Problem with page's button click event handler Pin
Not Active9-Jan-07 19:09
mentorNot Active9-Jan-07 19:09 
GeneralRe: Problem with page's button click event handler Pin
Tina P10-Jan-07 5:40
Tina P10-Jan-07 5:40 
GeneralRe: Problem with page's button click event handler Pin
Tina P11-Jan-07 13:09
Tina P11-Jan-07 13:09 
Questionimage casting in .NET Pin
Member 9571479-Jan-07 12:40
Member 9571479-Jan-07 12:40 
QuestionDisable a button Pin
ssircar19719-Jan-07 11:01
ssircar19719-Jan-07 11:01 
AnswerRe: Disable a button Pin
Jon Sagara9-Jan-07 11:32
Jon Sagara9-Jan-07 11:32 
You need to call Page.GetPostBackEventReference(), and then put a call to __doPostBack() in your JavaScript function.

Here's how I did it in my test application:

private void Page_Load (Object sender, System.EventArgs e)
{
String clientScriptFunc = String.Format ("DisableButton_{0}", btnSubmit.ClientID);

if (!IsClientScriptBlockRegistered (clientScriptFunc))
{
RegisterClientScriptBlock (
clientScriptFunc,
GenerateDisableButtonScript (btnSubmit, clientScriptFunc)
);
}

btnSubmit.Attributes.Add ("onclick", String.Format ("return {0}();", clientScriptFunc));
}

private String GenerateDisableButtonScript (Button btn, String clientScriptFunc)
{
StringBuilder script = new StringBuilder ();

script.Append ("<script language=\"javascript\">\n");
script.AppendFormat ("function {0}() {{\n", clientScriptFunc);
script.AppendFormat (" var myButton = document.getElementById('{0}');\n", btn.ClientID);
script.Append (" myButton.disabled = true;\n");
script.AppendFormat (" {0};\n", Page.GetPostBackEventReference (btn));
script.Append (" return true;\n");
script.Append ("}\n");
script.Append ("</script>\n");

return script.ToString ();
}

GenerateDisableButtonScript() will output a JavaScript function like the following:

<script language="javascript">
function DisableButton_btnSubmit() {
var myButton = document.getElementById('btnSubmit');
myButton.disabled = true;
__doPostBack('btnSubmit','');
return true;
}
</script>

<div class='ForumSig'></div>
QuestionNeeds assistance in displaying data in Tree view Pin
Skanless9-Jan-07 10:28
Skanless9-Jan-07 10:28 
QuestionASP.NET 2.0 and AJAX Pin
RX Maverick9-Jan-07 10:03
RX Maverick9-Jan-07 10:03 
AnswerRe: ASP.NET 2.0 and AJAX Pin
Christian Graus9-Jan-07 12:19
protectorChristian Graus9-Jan-07 12:19 
QuestionpageBaseType Pin
Brendan Vogt9-Jan-07 8:57
Brendan Vogt9-Jan-07 8:57 
AnswerRe: pageBaseType Pin
Christian Graus9-Jan-07 12:28
protectorChristian Graus9-Jan-07 12:28 
AnswerRe: pageBaseType Pin
Mike Ellison9-Jan-07 12:33
Mike Ellison9-Jan-07 12:33 
GeneralRe: pageBaseType Pin
Brendan Vogt11-Jan-07 7:26
Brendan Vogt11-Jan-07 7:26 
Questionhow to capture content markup within an httpmodule? [modified] Pin
jszpila9-Jan-07 8:44
jszpila9-Jan-07 8:44 
AnswerRe: how to capture content markup within an httpmodule? Pin
Mike Ellison9-Jan-07 12:29
Mike Ellison9-Jan-07 12:29 
GeneralRe: how to capture content markup within an httpmodule? Pin
jszpila10-Jan-07 6:24
jszpila10-Jan-07 6:24 
QuestionWeb Service Pin
Rahithi9-Jan-07 8:02
Rahithi9-Jan-07 8:02 
AnswerRe: Web Service Pin
ednrgc9-Jan-07 8:24
ednrgc9-Jan-07 8:24 
GeneralRe: Web Service Pin
Rahithi9-Jan-07 8:46
Rahithi9-Jan-07 8:46 
GeneralRe: Web Service Pin
ednrgc9-Jan-07 8:48
ednrgc9-Jan-07 8:48 
GeneralRe: Web Service Pin
Rahithi9-Jan-07 8:55
Rahithi9-Jan-07 8:55 
QuestionSecurity Issue Pin
alexfromto9-Jan-07 7:02
alexfromto9-Jan-07 7:02 
AnswerRe: Security Issue Pin
ednrgc9-Jan-07 7:13
ednrgc9-Jan-07 7:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.