Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 27th, 2007, 10:33 AM
Authorized User
 
Join Date: Jun 2003
Location: Great Dunmow, Essex, United Kingdom.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default page not refreshing

Hi All,

I have a page that simply has a button on it. In the button click event of the aspx.vb I attempt to disable the button before calling a procedure. The button does not disable until it's come out of the click event which defeates my purpose.


  #2 (permalink)  
Old February 27th, 2007, 10:40 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This is for obvious reasons because you have to wait for the server procedure to finish before the btn.enabled=false; command gets sent to the browser. To get around this, you will need to use some javascript. You can do something like this:

string sJavaScript = "";
sJavaScript = "if (typeof(Page_ClientValidate) == 'function') { ";
sJavaScript += "if (Page_ClientValidate() == false) { return false; }} ";
sJavaScript += "this.value = 'Please wait...';";
sJavaScript += "this.disabled = true;";
sJavaScript += Page.GetPostBackEventReference(this.btn);
sJavaScript += ";";
btn.Attributes.Add("onClick", sJavaScript);

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
  #3 (permalink)  
Old February 27th, 2007, 11:39 AM
Authorized User
 
Join Date: Jun 2003
Location: Great Dunmow, Essex, United Kingdom.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thanks, you've pointed me in the right direction. I've placed an onclickclient event and then created the following:

<script type="text/VBscript">
        sub DisableMe()
            btnCapture.Enabled = false
       end sub
</script>

When I press my button it drops into this event, but errors saying that btn Capture is an invalid object, but thats the name of my button

  #4 (permalink)  
Old February 27th, 2007, 12:54 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I am not sure what you are trying to achieve now. The above script will only disable the button but not raise a server side event??

The code I supplied above will disable the button and raise your server side click event and you do not need to supply a client side script block.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
  #5 (permalink)  
Old February 28th, 2007, 02:22 AM
Authorized User
 
Join Date: Jun 2003
Location: Great Dunmow, Essex, United Kingdom.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dparsons, Sorry you are correct in what I am trying to achieve. Should I place the javescript in a function and call it on the onclick event?

  #6 (permalink)  
Old February 28th, 2007, 11:06 AM
Authorized User
 
Join Date: Jun 2003
Location: Great Dunmow, Essex, United Kingdom.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dParsons,

it's nearly working, but this the compiler doesnt like

sJavaScript += Page.GetPostBackEventReference(this.btn);

searching the web, it appears that under asp2.0 GetPostBackEventReference now comes in the ClientScriptManager class, however I'm struggling to implement this within the Javascript. If you have any more thoughts on this, it would be much appreciated

  #7 (permalink)  
Old February 28th, 2007, 11:15 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Sorry that was 1.x code, in 2.0 it should be Page.ClientScript.GetPostBackEventReference

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #8 (permalink)  
Old February 28th, 2007, 11:32 AM
Authorized User
 
Join Date: Jun 2003
Location: Great Dunmow, Essex, United Kingdom.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, I tried your suggestion, but it didnt like it. However, I've changed it to this and it works.

        Dim cs As ClientScriptManager = Page.ClientScript
        Dim sJavaScript As String = ""
        sJavaScript = "if (typeof(Page_ClientValidate) == 'function') { "
        sJavaScript += "if (Page_ClientValidate() == false) { return false; }} "
        sJavaScript += "this.value = 'Please wait...';"
        sJavaScript += "this.disabled = true;"
        sJavaScript += cs.GetPostBackEventReference(btnCapture, "")
        sJavaScript += ";"
        btnCapture.Attributes.Add("onClick", sJavaScript)

Thanks very much for your help i'd never have got this under my own steam.

  #9 (permalink)  
Old February 28th, 2007, 11:39 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad you got it working.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to avoid page refreshing sarah lee Javascript How-To 2 June 12th, 2007 07:51 AM
refreshing XML withour refreshing the page sasidhar79 XML 1 January 12th, 2005 05:16 AM
refreshing a webcam page jake HTML Code Clinic 2 March 10th, 2004 05:38 PM
Problem In refreshing a page. zaeem Classic ASP Components 2 November 4th, 2003 12:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.