|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Disable a button in Javascript disables server-side codeI have a webform with an ImageButton on it. I have assigned an
OnClientScript that calls a javascript function that disables the button like this: <script language="javascript"> function DisableButton() { document.getElementById("ImageButton1").disabled = true; } </script> I have code-behind in the ImageButton1_Click sub that I want to process, but that code never runs if the OnClientScript disables the button. Is there a way to disable a button and run code-behind for it? Disabled form elements are not included in the post data. You will have to
re-enable them onsubmit. Bob Lehmann Show quoteHide quote "David Davis" <DavidDa***@discussions.microsoft.com> wrote in message news:AF16A284-0287-4635-9DCA-0EFB6FFF7F0D@microsoft.com... > I have a webform with an ImageButton on it. I have assigned an > OnClientScript that calls a javascript function that disables the button like > this: > > <script language="javascript"> > function DisableButton() { > document.getElementById("ImageButton1").disabled = true; > } > </script> > > I have code-behind in the ImageButton1_Click sub that I want to process, but > that code never runs if the OnClientScript disables the button. > > Is there a way to disable a button and run code-behind for it? > > Sounds more like you want the button disabled after the postback. If this is
what you want you could remove your OnClientClick event handler and if you Page_Load event handler if Page.IsPostBack then this.btnImage.Enabled = false; So when the page renders after processing the click event the button will be disabled. Show quoteHide quote "David Davis" wrote: > I have a webform with an ImageButton on it. I have assigned an > OnClientScript that calls a javascript function that disables the button like > this: > > <script language="javascript"> > function DisableButton() { > document.getElementById("ImageButton1").disabled = true; > } > </script> > > I have code-behind in the ImageButton1_Click sub that I want to process, but > that code never runs if the OnClientScript disables the button. > > Is there a way to disable a button and run code-behind for it? > > When you disable an asp button with client script it prevent the server side on click event from firing. What you need to do is to fire the onclick event of the button first before disabling the button. (view snippet below)
function DisableButton() { <%=Page.GetPostBackEventReference(ImageButton1 as Control)%> document.getElementById('ImageButton1').disabled = true; } Chineme Nnamdi
Problems with webcontrol and MultiView
access control in a Repeater from javascript Wizard, goto page, need to set values of a control in a Repeater RowDataBound bool to string ObjectDataSource - query being performed twice per page load? asp.net menu to show only parent, siblings and children as static menus Custom Web Control and Default Height/Width Set file extensions for FileUpload delete rows in dataset pls HELP: webpart acting as shared but should be user (spellchecked) |
|||||||||||||||||||||||