how to get a control's name

 Hi

  In a webform has some controls,i want to get the control's name to do other things

  How can i get a control's name,such as  DropDownlist

  Thanks a lot

0
yugiant
8/23/2008 4:08:22 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

5 Replies
486 Views

Similar Articles

[PageSpeed] 0

 This snippet loops through the controls in a webform and gives you the control type name.

 

foreach (Control cntrl in form1.Controls)
{
    Response.Write(cntrl.GetType().Name.ToString());
}
  
0
Lokira
8/23/2008 6:33:25 PM

How to write the code use vb.net

Thanks a lot

0
yugiant
8/24/2008 2:42:44 PM

Mark Lokira's answer as the answer.
 

For Each cntrl As Control In form1.Controls
    Response.Write(cntrl.[GetType]().Name.ToString())
Next

For future reference, use the following link to convert code:

http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx


Please mark the post(s) that have helped you as "Answer"


I'm better at brewing beer than crafting code but I have to do the latter to do the former. Will code for malt.
0
newsomer
8/24/2008 3:00:23 PM

 Hi

  i use

Response.Write(cntrl.[GetType]().Name.ToString() & "<br>")
the result is : 

Untitled PageLiteralControl
HyperLink
LiteralControl
LinkButton
LiteralControl
Label
LiteralControl
DropDownList
LiteralControl
Label


this just list the control's type's name.not the control's name,i think it is not the right answer

how can i work out my problem

thanks a lot

 

 

0
yugiant
8/24/2008 4:03:32 PM

 Change to:

 

For Each cntrl As Control In form1.Controls
    Response.Write(cntrl.ID)
Next
  
Please mark the post(s) that have helped you as "Answer"


I'm better at brewing beer than crafting code but I have to do the latter to do the former. Will code for malt.
0
newsomer
8/24/2008 5:45:49 PM
Reply:

Similar Artilces:

Getting a web form's properties to a Custom User Control
Ok. This is hopefully a simple question that someone could help me out on. I've researched but only found out how to get a user control properties to a web form. Problem:  Anyway, I have created a custom user control (Help button with a menu extender) which will be used on several pages. The menu that extends from the button will not be static, so I will want to load the right data (from my xml file) depending on which page the help button is on. For example, my custom user control will be on pages news and the other on media. Now, when the user control loads on the news page, I need ...

how to get a control ID from a bind field name / bound field (column) name from a formview's control
I have a form view which is bound to a table, now from codebehind file I need to apply some formatting based on some of the field's bound control. For example, if Formview1 is bound to Employee table, and it's item template has a control with ID "Label1" which is bound to "EmployeeJoinDate" . Now, I have a different table which has a list of field name(EmployeeJoinDate is one of them), all of which should be applied some formatting based on some condition. Now I can take two approach for that, but I am stuck at both:  1. If I can somehow get the contro...

getting today's date to appear on the .net web calendar control
try as I have i cannot get the today's date displayed at the bottom of my web calendar control.  is there any special option i should set on my calendar control properties ? Hi, what did you mean by at the bottom of my web calendar control ? Is is highlighting the day number of current date? Try this,Calendar1.SelectedDay = DateTime.NowCorrect me if I misunderstood your question. :)Alvin ChooiMicrosoft ASP.NETâ„¢ Enthusiast v1.1 / v2.0, Malaysia Blog : http://alvinzc.blogspot.com hi,   I can see the selected date eg if if do what you say:    Calendar1.Se...

Access Web Control's property within the Web Form
Hello, I have a Web Control which has a TextBox and a Button. I want to put this Control on a WebForm, then put some text in a Control's TextBox, press on Control's Button and be able to access text box's value from within the Web Form. That's my Control: _________________________________________________ public class Colo : System.Web.UI.UserControl { protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.Button Button1; public string Myval{ get{return (string)ViewState["myval"];} set{ViewState["myval"] = va...

Open file in browser or application getting the page's name as the file's name
Hi, I'm am trying to get a file to open in either a browser or application depending on the mime type. I'am using the following code in the page load. protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack)    { DocumentInfo document = (DocumentInfo)Session["View_Document"]; StreamFile(document.Document, document.DocumentName, document.FileType.MimeType); } } }private void StreamFile(byte[] fileData, string originalFileName, string mimeType) { try { Response.Clear(); Response.ContentType = mimeType; Response.AddHeader("Con...

Getting 'System.Web.UI.Control' does not contain a definition for 'DataItem' error on controls when placed inside an update panel which is in a template.
Using the June CTP, I;ve got an updatepanel inside the itemtemplate of a datalist which is now suppopsed to be supported (it works). I also have some asp controls (imagebutton, label) which get their values dynamically (DataBinder.Eval(Container.DataItem, "fieldname").ToString(). This would work fine before putting the updatepanel in the datalist itemtemplate, I now get the error in the title when building ('System.Web.UI.Control' does not contain a definition for 'DataItem') for each control... How can I dynamically assign the values to the controls in the datalist when also using upd...

How to get the Form's Name...?
Hi all, I want to Know how can i Get The Form's Name at Run-Time .Because i want to Render some Java Script Code and i need it. By default Form's name is "Form1" ,But user may be change it. Regards.Nothing Is Quite Impossible !!! You can get the form ID as follows: VB.NETMe.Form.ClientID C#this.Form.ClientID HTH,RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

Trying to load user control Dynamcially but getting error " Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server"
I am tired of this error and now writing a post.  My Web application has two pages. Page one has drop down list which redirect the page to another page . where I am going to load the usercontrol dynamically according to the choice of the user.     protected void ddlViewReport_SelectedIndexChanged(object sender, EventArgs e)  { if (ddlViewReport.SelectedIndex == 1) { Session["ReportType"] = ddlViewReport.SelectedIndex; Response.Redirect("RepReportingPage.aspx"); int crosspagevalue = ddlViewReport.SelectedIndex; } if (ddlViewReport.SelectedIndex == 2) {...

Getting the recreated control's id's by viewstate?
Hi How can i get the automaticly created fileupload control's id's by stroring them in the viewstate? Is it possible? or any other way to get them on the run-time? I can store button's click number and then create dynamic controls on the run-time and if i look at the source code i can see the auto-created id's but when i click submit button to upload files in fileupload controls i get an NullReferenceException. I guess when i click submit button all the id's gone because the page posts back. So i write this to read id's and assign to my fileupload control, here is the code for it...

It's all very fuzzy now...can make web request(?) but definately can't get web response from web service
Alas...trying to get a web service response from a web service that is part of the web site in Visual Studio.Net 3.5 appears to be impossible.  Infact, I've been ALL over the internet over the past couple of days looking at all types of fragmentory examples in all types of Microsoft languages to no avail. =========QUESTION:=========1.  How do I call a web service (the function to call is "WebService_BulkData") so that my aspx page will send it a SOAP request and print out the web service response data to the page?  The aspx page AND the web service are part of t...

Mozilla get's no style tag's from .net server.
I made a webform in web matrix, and it looks fine in IE. If I open the same link whit Mozilla, it looks like a disaster. When I look at the HTML source, there are no style tags as in IE. But when I save the HTML source from IE (the one whit style tags) and open it in Mozilla, it looks perfect. So the onley reason the webform looks wrong in Mozilla, is because the .net server detects Mozilla and not IE and sends a style less HTML source. Wy? Mozilla does support style tags. Is there a solution for this bug? Or is this a uh.. feature? ..Mivz Update, I have got some more info. It is ...

How can I get out of my Mozilla's browser the Winamp browser and get back the Google's or Mozilla's browser.
Please I have got to my browser ( I don't know how.) the Winamp browser he behave like virus stick in.But he doesn't has uninstalation section so I can't do anything to get him away from Mozilla's file. I'm not happy of Winamp's behave its like advertisement against a customer's will. Please is there any way to get him away from Mozilla?Please send me exact direction I have tried many ways but he is deeply inside the systeme so when I install new Mozilla he is always here ready to pester me. Thank you for an answer. Richard ...

How to Dist Between 'Web Forms' and 'HTML' Controls in VS 2005 IDE
I am using ASP.NET 2.  In books and articles, authors refer to and distinguish between 'Web' controls and 'HTML' controls.In the actual Vis Studio IDE toolbox for web forms,  I have one list of controls called 'Standard' containing controls like 'Button' etc. There is also a list labelled 'HTML'  with things like 'INPUT (button)' . There are a few other lists, but none labelled 'Web'. Where are the 'Web' controls found and what are they called in the IDE?  Same for the 'HTML' controls.   I see references in books to 'HTML' controls called 'TextBox', but I d...

Modify Web Control in Function by Passing in Web Control's ID as Parameter
Good day to all, I am trying to modify web controls through functions by passing in their ID as the parameter so that I can call the function whether a control's properties need to be modify. The rough idea I have is as follows: (Function, In VB) Function ModifyTextboxText(Byval SampleTextbox) SampleTextBox.text = "Textbox contents changed." End function (Calling the function) ModifyTextboxText(MyTextbox.id) Has anyone got any idea how I could proceed with the coding? Appreciate any help around here. Its for my school project. Thanks!...

Web resources about - how to get a control's name - asp.net.web-forms

Resources last updated: 12/17/2015 11:19:57 AM