Calling Javascript after postback

5 posts, 0 answers
  1. John Snyder
    John Snyder avatar
    43 posts
    Member since:
    Mar 2006

    Posted 02 Apr 2008 Link to this post

    When a user clicks on the "Save" button, I want to write a message that says "Saved at [current time]" (like Gmail does when saving a draft).  In order to get the current time I was going to use javascript.  How do I go about calling the Javascript to get the time and displaying it in my label?

    Some things to note:

    • I am using ASP.Net 2.0 and the latest build of Promethius
    • I am using a Master Page that has the AjaxManager and my other pages and usercontrols are all using the AjaxManagerProxy controls
    • I only want this message to be set when a certain button is clicked, not on every ajax request.

    Any help would be appreciated.

  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 02 Apr 2008 Link to this post

    Hi Dustin DeFoe,

    One of the benefits of the ajax technology is that it brings rich "client-side like" performance to your app. So in this line of thoughts you can go ahead and update the label with the DateTime.Now on the server. If you're going to do this with javascript, you do not need our Ajax controls for this.

    Best wishes,
    Steve
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John Snyder
    John Snyder avatar
    43 posts
    Member since:
    Mar 2006

    Posted 02 Apr 2008 Link to this post

    I am not wanting the server date and time, although that would be much easier.  Instead I am wanting the users local time and the only way I know to get that is by using javascript.  I still need to do the postback in order to perform the saving code.  Assuming the save worked  I want to show the "Saved at [time]" message.  I am trying to set this from the postback as I don't want to show a saved message before the postback.
  5. John Snyder
    John Snyder avatar
    43 posts
    Member since:
    Mar 2006

    Posted 02 Apr 2008 Link to this post

    I believe I have this working:

    HTML Code:
    <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="btnSave">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadScriptBlock1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
     
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
        <script language="text/javascript">  
            <%= _ScriptToLoad %> 
        </script> 
    </telerik:RadScriptBlock> 
     
    <asp:Label ID="lblValidation" runat="server" /> 
     
    <asp:Button ID="btnSave" runat="server" Text="Save" /> 
     

    VB Code
    Public _ScriptToLoad As String 
     
    Protected Sub btnSave_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnSave.Click  
        _ScriptToLoad = "D = new Date(); var H = D.getHours(); if (H > 12) {H = H-12};document.getElementById('" & lblValidation.ClientID & "').innerHTML = 'Saved at ' + H + ':' + D.getMinutes();" 
    End Sub 
     

    Dustin
  6. Chuck
    Chuck avatar
    30 posts
    Member since:
    Sep 2010

    Posted 24 Nov 2012 Link to this post

    Dustin,

    Many belated thanks for this!  I was using a different approach and setting the script on a label (which I had seen suggested elsewhere).  This worked for full postbacks but not for Ajax postbacks.  Your solution works for both and seems like so much less of a hack.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017