Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have searched and tried all of the examples that I could find for getting my program to update a textbox which is inside an UpdatePanel. I cannot get this to work.

What I have tried:

Here is my code

ASP.NET
<div class="w3-row-padding  w3-center w3-mobile">            
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:Button ID="cmdSubmit" runat="server" Text="Create Life Budget" CssClass="w3-button w3-black" Font-Bold="False" UseSubmitBehavior="False" />
    <br />
    <br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:TextBox ID="txtProgress" runat="server" Text="300" BackColor="Transparent" BorderStyle="None" CssClass="w3-center" ReadOnly="True" Width="300px" AutoPostBack="True"></asp:TextBox>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="cmdSubmit" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
</div>


VB
Protected Sub cmdSubmit_Click(sender As Object, e As EventArgs) Handles cmdSubmit.Click
    Master.HideMsg()
    CreateLifeBudget()
End Sub

Protected Sub CreateLifeBudget()
    '< Other Code>
    txtProgress.Text = "Processing " & iProgress & " of " & iProgressMax
    UpdatePanel1.Update()

    txtProgress.Text = "Processing " &amp; iProgress &amp; " of " &amp;    iProgressMax
    UpdatePanel1.Update()
End Sub


I am getting nothing to appear on the page. As I pasted the code into this question, could it be that since the actual code is inside another subroutine? I event tried it with the sub being Public.
Posted
Updated 17-Aug-20 20:58pm
Comments
Vincent Maverick Durano 11-Jul-19 15:55pm    
If you want to become a "real" web developer, then my advise is to get rid of UpdatePanel and use AJAX instead to do asynchronous updates.

 
Share this answer
 
TextBoxes are populated little bit differently in updatepanels.

Then they will not update current value unless you focus on the textbox and empty it first. Strange, but it works like that.

This is C#

First set focus and Empty

TextBox1.Focus();
TextBox1.Text = string.Empty;

Then set values to your textbox with Attributes.Add

var value1 = row.Cells[0].Text;
TextBox1.Attributes.Add("value", value1);

This will update your textbox as often as you like in same updatepanel
 
Share this answer
 
v2
Comments
CHill60 18-Aug-20 4:18am    
"TextBox1.Text = string.Empty;" is updating the current value of the textbox so what you are saying doesn't really make sense. There is no need to set focus before changing the value. TBH OP was probably not checking isPostBack and the value was getting reset to the original

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900