Results 1 to 10 of 10

Thread: [*resolved]how can I detect and convert html tags to text?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    [*resolved]how can I detect and convert html tags to text?

    lets say I have a textbox and the user enters some html tags in it. I want those to show up as text (well asp engine gives me an error if I enter html tags when submitting the value of the textbox). php had a simple function that converted all those to simple text. what should I do in asp.net?
    Last edited by MrPolite; Jul 8th, 2003 at 05:29 PM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    If i understand you correctly the Server.HTMLEncode method should be able to help you out here - that help for a start?

    Cheers

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by powdir
    If i understand you correctly the Server.HTMLEncode method should be able to help you out here - that help for a start?

    Cheers
    hmm well I dont know how to use it. As soon as the page is submitted, before the click event for my button fires, I get the error message: A potentially dangerous Request.Form value was detected from the client (txtMessage="...dasdasdf <br>").


    how can I fix this?
    Here's all my page does: there is a textbox, and a button that shows teh content of the textbox in a label. Now if the user enters html tags in the textbox I get that error.... dunno how I can use the htmlencode function
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Thats the new security in ASP.NET 1.1. To bypass it just put ValidateRequest="false" in the @Page attribute of the page that is is throwing the exception.

  5. #5
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    ...something like

    Code:
        dim str as string
        str = Server.HTMLEncode(MyTextBox.text)
    lets say your textbox (MyTextBox) has contains tags - which yours does - the above function will apply encoding to the contents, preventing malicious upload of HTML.

    So....

    Code:
        dim str as string
        str = Server.HTMLEncode("<P>") 'paragraph tag will output as &lt;P&gt;
    likewise Server.HTMLDecode does the opposite

    That help?

    Cheers

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by powdir
    ...something like

    Code:
        dim str as string
        str = Server.HTMLEncode(MyTextBox.text)
    lets say your textbox (MyTextBox) has contains tags - which yours does - the above function will apply encoding to the contents, preventing malicious upload of HTML.

    So....

    Code:
        dim str as string
        str = Server.HTMLEncode("<P>") 'paragraph tag will output as &lt;P&gt;
    likewise Server.HTMLDecode does the opposite

    That help?

    Cheers
    umm well ok I'm sure there is nothign wrong with that line of code, but the problem is that the compiler never actually runs the code, it gives me the error before it would fire any events.

    just try this, put a textbox and a button on a project. run it, and type a <br> in the textbox. when you press the button and the textbox's contents are submitted you'll get an error

    I'm sure there is a simple solution to this, I just dunno how to get around it because I'm new to asp

    so I'm talking about 2 problems in this post
    1- how to convert those tags to plain text -> you answered me, htmlEncode(), thanks
    2- how to aviod that error -> still dunno
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Originally posted by MrPolite
    umm well ok I'm sure there is nothign wrong with that line of code, but the problem is that the compiler never actually runs the code, it gives me the error before it would fire any events.

    just try this, put a textbox and a button on a project. run it, and type a <br> in the textbox. when you press the button and the textbox's contents are submitted you'll get an error

    I'm sure there is a simple solution to this, I just dunno how to get around it because I'm new to asp

    so I'm talking about 2 problems in this post
    1- how to convert those tags to plain text -> you answered me, htmlEncode(), thanks
    2- how to aviod that error -> still dunno
    Dude apparently you did'nt read my post.

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    As DevGrp said:
    ValidateRequest="false"
    That is your problem. I had to do it to this page of mine to get it to work:
    http://www.variantx.com/Main/DevTools/HTMLEncoder.aspx

  9. #9

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by DevGrp
    Dude apparently you did'nt read my post.
    lol sorry I wasnt ignoreing you or anything, I swear I didnt even see your post my bad, gotto open my eyes better. thanks for the answer


    edit: what other things does that ValidateRequest do?
    Last edited by MrPolite; Jul 8th, 2003 at 05:45 PM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I dont think it does anything else.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width