This is a migrated thread and some comments may be shown as answers.

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

2 Answers 46 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Martino
Top achievements
Rank 1
Martino asked on 11 Jun 2014, 09:01 AM
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 Answers, 1 is accepted

Sort by
0
Martino
Top achievements
Rank 1
answered on 11 Jun 2014, 12:04 PM
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

0
Martino
Top achievements
Rank 1
answered on 12 Jun 2014, 08:53 AM
Tags
Ajax
Asked by
Martino
Top achievements
Rank 1
Answers by
Martino
Top achievements
Rank 1
Share this question
or