Jurioli / Blazor.WebForm.Components

ASP.NET Web Forms System.Web.UI.WebControls Razor Components For Blazor WebAssembly, Blazor Hybrid, Blazor Server.
MIT License
44 stars 9 forks source link

Textbox fails to update when post triggered from same button #3

Closed scyb3r closed 1 year ago

scyb3r commented 1 year ago

Sample code attached. If i hit the Test 1 button, the text in the textbox shows "test". If i change the text in the textbox manually, then hit the same Test 1 button again, the textbox is not updated. This is a bug, or at least not the intended behavior according to WebForms. Can you help me understand why this is happening and what a good workaround would be?

@page "/" @using Blazor.WebForm.UI.ControlComponents; @using System.Web.UI; @inherits ControlComponent

<asp.TextBox @ref="txtTest"></asp.TextBox>

<asp.Button @ref="btnTest" OnClick="btnTest_Click">Test 1</asp.Button>

<asp.Button @ref="btnTest2" OnClick="btnTest2_Click">Test 2</asp.Button>

@code{

asp.Button btnTest;
asp.Button btnTest2;
asp.TextBox txtTest;

protected void btnTest_Click(object sender, EventArgs e)
{
    this.txtTest.Text = "test";
    this.RequestRefresh();
}

protected void btnTest2_Click(object sender, EventArgs e)
{
    this.txtTest.Text = "1234";
    this.RequestRefresh();
}

}

Jurioli commented 1 year ago

Maybe you can add AutoPostBack="true" to the TextBox. The TextBox is not updated because the two input tag renderings output the same "test" so that blazor thinks that the value of the input has not been updated.

Behavior is the same:

@page "/"

<input value="@this.text" />

<button @onclick="this.OnCliek1">test 1</button>

<button @onclick="this.OnCliek2">test 2</button>

@code {
    private string text;

    private void OnCliek1()
    {
        text = "test";
    }

    private void OnCliek2()
    {
        text = "1234";
    }
}
scyb3r commented 1 year ago

Friend,

Thank you for the feedback. That does indeed help. I’m not used to putting AutoPostBack on most textboxes, but for my purpose, that will do.

Great job on this project. Hope to see more updates.

Thank you 😊

From: Jurioli @.> Sent: Wednesday, March 22, 2023 9:18 PM To: Jurioli/Blazor.WebForm.Components @.> Cc: scyb3r @.>; Author @.> Subject: Re: [Jurioli/Blazor.WebForm.Components] Textbox fails to update when post triggered from same button (Issue #3)

Maybe you can add AutoPostBack="true" to the TextBox. The TextBox is not updated because the two input tag renderings output the same "test" so that blazor thinks that the value of the input has not been updated.

— Reply to this email directly, view it on GitHub https://github.com/Jurioli/Blazor.WebForm.Components/issues/3#issuecomment-1480580132 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHDHGUOBJDW4LV5DJH7SVTW5PFHHANCNFSM6AAAAAAWEAFSXM . You are receiving this because you authored the thread. https://github.com/notifications/beacon/ABHDHGWQI3UPS5DYKU2BZGTW5PFHHA5CNFSM6AAAAAAWEAFSXOWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSYH7OCI.gif Message ID: @. @.> >