CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2010
    Posts
    130

    [RESOLVED] Html decode?

    I am importing an array of names from the db and for each element in the array I am creating a radiobutton. The radiobutton's ID corresponds to the array name. Certain names contain special characters and are therefore written in ASCII HTML character code. I later perform some operations to determine which radiobutton has been selected but then the radiobuttons with the HTML ID are not recognized. I tried inserting the following to ensure the ID stays in HTML character code form throughout the code but it doesnt seem to work:

    Code:
    selectedRbtnID = Server.HtmlDecode(radiobutton.ID);
    Is there another way to tackle this?

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Html decode?

    Hi,

    I would suggest having a different identifier. If possible try to go for a numeric value or a combination of simple letters and numbers. If you can change the database and assign the relevant records unique identifiers do that. I would also add that the identifiers don't need to come from the database. You can generate them in your code after you retrieve the data. This can be as simple as starting with an initial value and just incremeting and assigning it as an id.

  3. #3
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Html decode?

    try this...

    Code:
    selectedRbtnID = HttpUtility.UrlDecode(radiobutton.ID);
    you will need to add a reference to the System.Web namespace(if you don't already have it).

    I tested with this, and it converted it correctly...
    Code:
    string test = HttpUtility.UrlDecode("hello%20world");
    
    // Output
    //      "hello world"
    ===============================
    My Blog

  4. #4
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Html decode?

    Quote Originally Posted by eclipsed4utoo View Post
    try this...

    Code:
    selectedRbtnID = HttpUtility.UrlDecode(radiobutton.ID);
    you will need to add a reference to the System.Web namespace(if you don't already have it).

    I tested with this, and it converted it correctly...
    Code:
    string test = HttpUtility.UrlDecode("hello%20world");
    
    // Output
    //      "hello world"
    Good point. I would still prefer to have an identifier that doesn't include spaces or any special characters...

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Html decode?

    and how about not decoding this string at all but putting it in the Tag property and give the radiobuttons other names
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  6. #6
    Join Date
    Dec 2009
    Posts
    22

    Re: Html decode?

    If it is the id attribute of the buttons you are talking about then I would also suggest used a different identifier. If you have an auto incrementer on the rows in the database, this would be an ideal choice.

    Something like id="button_1234"

    you could also do it with javascript? I'm don't know the specifics of you application, but i know that you can add arbitrary data to any element using the .data function in JQuery.
    An attached event handler could then make the correct request once the button is selected.

  7. #7
    Join Date
    Jan 2010
    Posts
    130

    Re: Html decode?

    Thank you very much, now it works!

    I took Jonlist's advice and used "_" in the ID instead of "." and then used the following to decode the ID:

    Code:
    rbtnSkill.ID = HttpUtility.HtmlDecode(criterium[i].Skill) + "_" + eNum;

Tags for this Thread

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

Featured