Button not causing postback
I've got a Button, with the corresponding aspx being this:
<asp:Button runat="server" ID="checkall" OnClientClick="setAllWeeks(true);" 
    AutoPostBack="true" Text="Check All" />
This is because the logic I want to happen for th开发者_运维知识库is particular button on the server side is validation that occurs every time in the Page_Load event, and additionally, I want a Javascript function to be called first. However, when I click the button, it doesn't seem to cause a postback the first time, only the second time that it's posted.
How can I guarantee that the client-side function is executed first, and then a postback is generated?
Do the following code:
<asp:Button runat="server" ID="checkall" OnClientClick="return setAllWeeks(true);" 
    AutoPostBack="true" Text="Check All" />
And inside the setAllWeeks() function do the following :
function setAllWeeks(val) {
    //If everything all right
    If(True)
    {
      //Do something
      return true;   
    }
    else
      return false;
}
If the function behaviors is all right return true else return false.
Note: All paths of the function should return a value(Boolean value).
This happened to me a few times. The cause was that my function specified in OnClientClick returned 'false'.
Hoe does that 'setAllWeeks' look like? Maybe it's returning false?
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论