Link to home
Create AccountLog in
Avatar of drl1
drl1Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Updatepanel showing different value on page than in source code

I have some a textbox and a button in an updatePanel. On page load i run a function called loadNumber(). When the button in the updatePanel is clicked it also runs the loadNumber function. The loadNumber function simply, queries the database and returns a number (lets say that the numbers in the database are 1,2,3) which is displayed in the textbox. So when i click the button in the updatePanel again, it executes the loadNumber function once more and then displays a different number which is 2 or 3 (it stores number 1 after submit so it shouldnt show it again).

This works perfectly fine when i am looking at the page, however the extremely strange thing is that when i look at the source code it is showing a different number than what is showing on the page so for example the textbox on the page could be showing the number "2" but the source code on the page will be showing the number "3". I dont understand, why on earth is the page rendering what is showing up differently in source code? Just for extra information, if i remove the update panel (i.e. so that the page submits fully rather than a partial page submit then it works fine).

ASPX file
<form runat="server">
<div id="mainContainer">

            <asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" style="border:2px solid black; padding:30px;"><ContentTemplate>

                <asp:TextBox ID="test_tb" runat="server"></asp:TextBox><asp:TextBox ID="test2_tb" runat="server"></asp:TextBox><asp:TextBox ID="test3_tb" runat="server"></asp:TextBox>
                <asp:Button ID="submit" runat="server" width="400" text="submit" OnClick="submitMS"/>
                <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                        <ProgressTemplate>Loading next number please wait</ProgressTemplate>
                </asp:UpdateProgress>
            </ContentTemplate></asp:UpdatePanel>

</div>
</form>

Open in new window


Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            loadnextNumber()
        End If
    End Sub


    Public Sub loadnextNumber()

        select_qry = "SQL query which returns a number"
        objData = getSqlQueryObj(select_qry)


        While objData.Read()
            test_tb.Text = objData("number").ToString
        End While
    End Sub

   

    Public Sub submitMS(ByVal sender As Object, ByVal e As System.EventArgs)
 
           loadnextNumber()

    End Sub

Open in new window


Live page to see this behaviour happening:

the source code does actually change between requests (so it does not stay as the initial page request) however it shows a different value than what is shown on the page. I have just setup a test page for you to see:

https://www.panelbase.net/updatepanel.aspx

Click the submit button and compare the value in the textbox with the source code in firefox. I already checked firebug and i know it does display the correct value however the problem i am having is this:

- You submit the page

- The next value loads in the textbox

- I use javascript on the page to check the value before it is submitted

However javascript is looking at the value of the source code and NOT the page so the comparison is wrong.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account