skip to Main Content

I’m trying to remove a <br /> from my page.aspx file dynamically according to information received from a previous page. I’ve tried giving the br an id and attempting to remove it like this:

in page.aspx:

<br id="Break" />

in page.aspx.cs:

Page.Form.Controls.Remove(Break);

This doesn’t work and it tells me that the name ‘Break’ does not exist in the current context.

I’m using Page.Form.Controls.Remove in other lines of my code and it’s working perfectly fine but when I try and remove a <br /> it always gives me an error.

Is there another way to dynamically remove <br /> from my page.aspx that I could use?

2

Answers


  1. You can try to use Replace function

    string str = WebUtility.HtmlDecode(yourText);
    str = txt.Replace("<br>", Controlchars.NewLine);
    str = txt.Replace("<br/>", Controlchars.NewLine);
    
    Login or Signup to reply.
  2. Yes, if you do <br runat="server" id="break" />. but set this.break.Visible = false; instead of Remove.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search