Can't read server-side setted values in js pageLoad

3 posts, 0 answers
  1. Martino
    Martino avatar
    4 posts
    Member since:
    Sep 2013

    Posted 11 Jun 2014 Link to this post

    Hi guys,

    I've an aspx web form with a radAjaxManager, which handles some autopostback input and refreshes a custom ascx

    In the ascx there is some hiddenField which is setted server side, depending on aspx' input values, and some javascript

    I want to execute some javascript function depending on the hiddenField value, so I'm checking it in a js pageLoad event

    The problem is, despite the fact html values are updated (I can see it with firebug), the pageLoad sees always the same value

    If I do something simple as alert($(hiddenField).val()) I see always the original, entire-page-loaded value, and not the ajax updated value

    What's wrong? Some clue?

    Thank you,

    Martino
  2. Martino
    Martino avatar
    4 posts
    Member since:
    Sep 2013

    Posted 11 Jun 2014 Link to this post

    this is the simplest case in which the problem can be reproduced, hope it helps:

    .aspx :
     
    <script src="../resources/script/jquery.js"></script>
    <tlk:RadScriptManager runat="server" ID="RadScriptManager1"></tlk:RadScriptManager>
         
        <tlk:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <tlk:AjaxSetting AjaxControlID="txtInput">
                    <UpdatedControls>
                        <tlk:AjaxUpdatedControl ControlID="pnlDst"/>
                    </UpdatedControls>
                </tlk:AjaxSetting>
            </AjaxSettings>
        </tlk:RadAjaxManager>
     
        <asp:Panel ID="pnlSrc" runat="server">
            <asp:TextBox ID="txtInput" runat="server" AutoPostBack="true"></asp:TextBox>
        </asp:Panel>
        <asp:Panel ID="pnlDst" runat="server">
            <asp:HiddenField ID="hidExecute" runat="server" />
            <a href="#" onclick="alert($('#<%=hidExecute.ClientID%>').val()); return false;">
               check hiddenfield value
            </a>
            <script type="text/javascript">
     
                var hidExecute = $('#<%=hidExecute.ClientID%>');
     
                function pageLoad() {
     
                    var exe = $(hidExecute).val();
     
                    alert(exe);
                }
            </script>
        </asp:Panel>


    .aspx.cs:

           
    protected void Page_Load(object sender, EventArgs e)
    {
        var txt = string.Empty;
     
        if (string.IsNullOrEmpty(txtInput.Text))
        {
            txt = "VOID";
        }
        else
        {
            for (int i = txtInput.Text.Length - 1; i >= 0; i--)
            {
                txt += txtInput.Text[i];
            }
        }
     
        hidExecute.Value = txt;
    }

    You can see the result here

    The page alerts 'VOID' when the hiddenField is empty, and the hiddenField shoud be filled with the textBox value reversed; you can check the actual hiddenField value by clicking the link, it's the same way it's done in the pageLoad so I would expect the same results

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Martino
    Martino avatar
    4 posts
    Member since:
    Sep 2013
Back to Top