code_junkie

Javascript confirmation dialog - ASP.NET

Nov 14th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <asp:Button ID="btnUploadFiles" runat="server" OnClick="buttonSubmit_Click" Text="Update" />
  2.  
  3. protected void buttonSubmit_Click(object sender, EventArgs e)
  4. { try{// update the database
  5. // change label text to tell the user update succeeded}
  6. catch(Exception ex){...}
  7. }
  8.  
  9. protected void buttonSubmit_Click(object sender, EventArgs e)
  10. {
  11. try
  12. {
  13. // update the database
  14. // change label text to tell the user update succeeded
  15. label.Text = "Message";
  16. string js = "function hideLabel(){document.getElementById('" + label.ClientID + "').style.display = 'none'};setTimeout(hideLabel, 5000);"
  17. ClientScript.RegisterClientScriptBlock(this.GetType(), "test", js ,true);
  18. }
  19. catch(Exception ex){...}
  20. }
  21.  
  22. <script type="text/javascript">
  23. function hideLabel()
  24. {
  25. // replace yourLabelID with <%=YourLabelID.ClientID%> if it's a .NET Label control
  26. document.getElementById('yourLabelID').style.display = 'none';
  27. }
  28. setTimeout('hideLabel()', 5000);
  29. </script>
  30.  
  31. function hideLabel(label)
  32. {
  33. $(label).hide();
  34. }
  35.  
  36. $(document).ready( function() {
  37. var label = $('#labelID');
  38. setTimer(function() { hideLabel(label); ),5000);
  39. });
Add Comment
Please, Sign In to add comment