Home > Back-end >  Is it possible to dynamically remove a <br /> in asp.net?
Is it possible to dynamically remove a <br /> in asp.net?

Time:12-15

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?

CodePudding user response:

Yes, if you do <br runat="server" id="break" />. but set this.break.Visible = false; instead of Remove.

CodePudding user response:

You can try to use Replace function

string str = WebUtility.HtmlDecode(yourText);
str = txt.Replace("<br>", Controlchars.NewLine);
str = txt.Replace("<br/>", Controlchars.NewLine);
  • Related