Replace text from a textbox when the user input the same textbox

Asked

Viewed 65 times

-1

I have a textbox where, through another page I pass you an e-mail.

txtemail.text = "[email protected]"

And when my page makes the load, in that textbox appears: [email protected].

Only if I try to make a new one input in that textbox he does not keep, always staying with the [email protected].

I have the AutoPostBack="true", I’ve tried too OnTextChanged but I couldn’t.

I needed something like that.

txtemail.text = txtemail.text.newInput()

This is my textbox

<div class="form-group">
<asp:Label ID="LEmailP" runat="server" Text="Para :" Font-Size="Medium" Font-Bold="true"></asp:Label>
<asp:TextBox CssClass="labelEmail" ID="txtEmailP" required="true" MaxLength="50" runat="server" type="text" TabIndex="2" AutoPostBack="true" pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$" title="ex: [email protected]" placeholder="Titular Email"></asp:TextBox>
</div>

I pass my email per page here ( put on page load )

string email = Request.QueryString["email"]; txtEmailP.Text = email;

  • Post all relevant part of the code

  • @Leandroangelo if I try to change the value of mine txtEmailP on the page where I am, how I have the AutoPostBack="true" she automatically switch me to the email I passed by linkRequest.QueryString["email"]

1 answer

1


Well you didn’t put your code, but in view of the behavior, it is possible to state that you are assigning the value passed on QueryString for your input txtEmail in the event of Page_Load(). And how you attributed the behavior of AutoPostBack="True" for it or any other component on the screen. Every time this feature is activated you will go through the Page_Load()again and will receive the amount you are informed on QueryString.

The solution is simple, add the condition so that this assignment occurs only when the page load is not coming from a PostBack

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        txtEmail.Text = Request.QueryString["email"];
    }

}
  • You are absolutely right ! A hug worked perfectly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.