Solved

c#, code behind with html5

Posted on 2016-09-08
2
27 Views
Last Modified: 2016-09-09
on c# code behind, how can i get id name called 'DEP_FIRST_NAME_1'?  not value of the DEP_FIRST_NAME_1

<input runat="server" type="text" class="form-control" id="DEP_FIRST_NAME_1" name="DEP_FIRST_NAME_1" placeholder="First Name" />

Open in new window

0
Comment
Question by:ITsolutionWizard
  • 2
2 Comments
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41790620
use this to referring to the control in code behind:
System.Web.UI.HtmlControls.HtmlInputText t = (System.Web.UI.HtmlControls.HtmlInputText)this.FindControl("DEP_FIRST_NAME_1");
            if (t != null)
            {
                Response.Write(t.ID + ":" + t.Value);
            }

Open in new window

to get the "ID" , you may do a loop at code behind, like:
foreach (Control c in Page.Controls)
            {
                foreach (Control childc in c.Controls)
                {
                    Response.Write(childc.ID + "<br>");
                }
            }

Open in new window

or you want to get it from jQuery?
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 41790627
for jQuery, you can try:
<script src="https://code.jquery.com/jquery-3.1.0.slim.min.js"
	    integrity="sha256-cRpWjoSOw5KcyIOaZNo4i6fZ9tKPhYYb6i5T9RSVJG8="
	    crossorigin="anonymous"></script>

<script language="javascript">
    $('#form1 input').each(function (id, value) {
        console.log(this.id);
    });
</script>

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question