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).
From your query i understood that you are not using "!IsPostBack" property in PageLoad which avoid calling the function loadNumber() when button click.
Second thing that i suspect is the textbox is not in UpdatePanel which is not being updated in the source code when second time loadNumber method is called. Ensure textbox is in UpdatePanel so that the updated value (lets say '3') will bind to the textbox.
VB file
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
Well you see that is what i originally thought, if it showed the old value in the textbox i.e. the value "1" from the previous submit then this would be completely understandable however it is showing another value different to what has been submitted and
different to what is on the page. So for example:
Page loaded=> show value of 1 in textbox.
I clicked the submit button => the value 1 in the textbox has been submitted and now the value 2 is retrieved from the database & loaded into the textbox.
So when i view the source i expected to have a value of 2 in the textbox however the value of 3 shows up. I dont understand how/why it is loading the next value sometimes. It is as if it is submitting itself once for the page and another time without me
knowing for the source code.
View Source in browsers does not generally display any dynamic changes made to the HTML (i.e. changes resulting from an asynchronous post-back on an UpdatePanel). It will just give you the HTML that was received from the initial page request. If you're using
Firefox, using Firebug to inspect the markup should show you dynamic changes. If you've got IE8 the Developer Tools will do the same thing. If you've got IE6 or 7 (or 8), the
FullSource extension will display the HTML for what's currently displayed, not the initial page response.
Thanks Chetan but as i mentioned above, 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.
rezelute
Member
108 Points
93 Posts
Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 15, 2012 12:30 PM|LINK
Hi,
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).
Any ideas are very much appreciated!! Thank you.
GMR Poola
Member
234 Points
45 Posts
Re: Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 15, 2012 01:11 PM|LINK
Hi,
From your query i understood that you are not using "!IsPostBack" property in PageLoad which avoid calling the function loadNumber() when button click.
Eg: protected void Page_Load(object sender,EventArgs e)
{
if(!IsPostback)
loadNumber();
}
}
Second thing that i suspect is the textbox is not in UpdatePanel which is not being updated in the source code when second time loadNumber method is called. Ensure textbox is in UpdatePanel so that the updated value (lets say '3') will bind to the textbox.
GMR Poola
rezelute
Member
108 Points
93 Posts
Re: Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 15, 2012 01:35 PM|LINK
I can confirm that it has nothing to do with either, i am using both. The textbox is in the updatepanel and i am using 'Not isPostback'.
rezelute
Member
108 Points
93 Posts
Re: Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 15, 2012 03:06 PM|LINK
If you test the code below you will notice that what appears on the page and then view source code are different results.
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>Kenshinofkin
Member
94 Points
99 Posts
Re: Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 15, 2012 07:44 PM|LINK
This is expected behaviour. You are performing a partial page postback and the source view only shows full postbacks.
rezelute
Member
108 Points
93 Posts
Re: Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 15, 2012 07:50 PM|LINK
Well you see that is what i originally thought, if it showed the old value in the textbox i.e. the value "1" from the previous submit then this would be completely understandable however it is showing another value different to what has been submitted and different to what is on the page. So for example:
Page loaded=> show value of 1 in textbox.
I clicked the submit button => the value 1 in the textbox has been submitted and now the value 2 is retrieved from the database & loaded into the textbox.
So when i view the source i expected to have a value of 2 in the textbox however the value of 3 shows up. I dont understand how/why it is loading the next value sometimes. It is as if it is submitting itself once for the page and another time without me knowing for the source code.
chetan.sarod...
All-Star
65729 Points
11133 Posts
Re: Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 16, 2012 03:24 AM|LINK
View Source in browsers does not generally display any dynamic changes made to the HTML (i.e. changes resulting from an asynchronous post-back on an UpdatePanel). It will just give you the HTML that was received from the initial page request. If you're using Firefox, using Firebug to inspect the markup should show you dynamic changes. If you've got IE8 the Developer Tools will do the same thing. If you've got IE6 or 7 (or 8), the FullSource extension will display the HTML for what's currently displayed, not the initial page response.
http://forums.asp.net/t/1819261.aspx/1?Weird+prob+asp+updatepanel+shows+up+when+I+View+Source+a+rendered+page+
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
rezelute
Member
108 Points
93 Posts
Re: Bizarre UpdatePanel behaviour - What renders on page is showing differently in source code
Nov 16, 2012 08:26 AM|LINK
Thanks Chetan but as i mentioned above, 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.