access html controls from C# in code behind

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bradwoody
    New Member
    • Jul 2007
    • 1

    access html controls from C# in code behind

    ASP.Net and C#

    I am having trouble determining how to manipulate html controls via javascript AND access those same controls in the C# code behind. Here's the scoop:

    I am making an advanced search page, consisting of a table where each row has (in this order):
    - checkbox – to indicate whether to return the column
    - label
    - textbox – to enter search criteria

    On some rows, though, I replaced the textbox with radio buttons so users can search on True and False. At first I used ASP radio button controls, but I changed them to html controls so I could control them with javascript – so when the user UNchecks a checkbox, I want the corresponding radio buttons to both be unselected. So I made the checkbox and radios be html controls. Works great.

    The problem: I'd like to build the SQL statement in C# in the code behind, but I don't know how to get the state of the html checkboxes and radio buttons to the code behind page.

    I know I can do something similar to what I want if the html control is a textbox. I know I can access the value by:
    Request["control's ID"].ToString()
    but I can't get the checkboxes and radios.

    Any suggestions?
  • Mr Gray
    New Member
    • Apr 2008
    • 47

    #2
    You can use the server controls e.g.:

    Code:
    <asp:radiobuttonlist id="rbl1" runat="server">
    as you fisrt intended and you can access it in the client side by using this in the cs file:

    Code:
    rbl1.ClientID;
    or if it is a dynamically created list you can use:

    Code:
    rbl1.UniqueID;
    This way in the server side code you can access the values as you would normally:

    Code:
    rbl1.SelectedIndex;
    I know the code is not entirely correct but it will help you search for more ideas.

    Comment

    Working...