Web Custom Control - Create Control, Assign ID Name, ID Name Changes

 I wrote this web custom control, and finally got all the embedded images and script files to embed, and display properly.

But when I assign a name to the ID of the Control, the server changes the ID Name.

So I have a control called txtMovieEmbed, and I assign the ID as txtMovieEmbed.

But when the control renders, the name changes to ctl00_ContentPlaceHolder2_txtMovieEmbed

 

txtMovieEmbed = New TextBox
txtMovieEmbed.Width = 325
txtMovieEmbed.CssClass = "FormControl"
txtMovieEmbed.ReadOnly = True
txtMovieEmbed.Text = MovieEmbedCode
txtMovieEmbed.ID = "txtMovieEmbed"
txtMovieEmbed.Attributes.Add("onclick", "MovieEmbed()")
Controls.Add(txtMovieEmbed)
txtMovieEmbed.RenderControl(writer)  

 

I have embedded javasscript that fires on the onclick event
 

Function MovieEmbed() {
        document.getElementById('ctl00_ContentPlaceHolder2_txtMovieEmbed').focus();
        document.getElementById('ctl00_ContentPlaceHolder2_txtMovieEmbed').select();
    } 
I can hard code the new name in, but I want to make the control flexible where you can drop the control anywhere on any page,
 and my javascript picks up the correct id name. 
Any suggestions or wisdom is a huge thanks, and will allow me to create  good controls.
 
0
jkirkerx
3/3/2008 7:41:05 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

3 Replies
1186 Views

Similar Articles

[PageSpeed] 22

There are two different IDs available: ID, which is the one you are setting, and the one that you would use to programmatically find the control, alter it, etc, on the server.

The second ID is the ID a controls is ClientID, which is the ID that is rendered for use on the client-side (i.e., from within the webpage while it is being viewed, such as what javascript would reference).

 If you use the ClientID in your javascript code, you'll never have to hard-code the id. 

If you do a Google Search on NamingContainers, you should be able to get more information on why controls are renamed.


---------------------------------------
MCP - Web Based Client Development .NET 2.0
0
ps2goat
3/3/2008 11:07:21 PM

I will spend some time reading info on naming containers, I understand it more now after reading a couple of articles.

0
jkirkerx
3/4/2008 12:17:06 AM

 Ended up creating all of the controls in preinit, to base the names of all the added controls on the ID of the original control.

 

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

		ibTeamMember = New ImageButton
		ibTeamMember.ID = "ib" & [ID]
		ibTeamMember.AlternateText = "Photo Image"
		ibTeamMember.ImageUrl = [MemberImageSource]
		ibTeamMember.ImageAlign = ImageAlign.AbsMiddle
		Controls.Add(ibTeamMember)

		Panel_TeamMember = New Panel
		Panel_TeamMember.ID = "Panel_" & [ID]
		Controls.Add(Panel_TeamMember)

		HME_TeamMember = New AjaxControlToolkit.HoverMenuExtender
		HME_TeamMember.PopupControlID = Panel_TeamMember.ID
		HME_TeamMember.TargetControlID = ibTeamMember.ID
		HME_TeamMember.HoverCssClass = "DoctorDetails"
		HME_TeamMember.OffsetX = 0
		HME_TeamMember.OffsetY = 5
		HME_TeamMember.PopDelay = 25
		HME_TeamMember.PopupPosition = HoverMenuPopupPosition.Bottom
		Controls.Add(HME_TeamMember)

		MyBase.OnInit(e)

	End Sub
  
0
jkirkerx
3/5/2008 12:25:07 AM
Reply:

Similar Artilces:

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

Custom Web Control inside another Custom Web Control
Hi I created a custom web control (CusWebNew) that displays some textboxes by adding them to the ControlCollection of the webcontrol. I also created a custom webcontrol (CustWebButton) that inherts from Button control, and overrided the OnClick function. When I use CustWebButton on a regular web form, it seems to function correctly. However, when I added to be part of the ControlCollection of CustWebNew, it stops to work.   Any ideas why? Thanks Hey, What do you mean by stops to work?  Explain what you are trying to do with it and what it doesn't do.Brian"Trust in the...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

Server Web User Control or Web Custom Control
Ok, I made a DataGrid I like, stuck it in a Web Control Lib, and then to my toolbar. Now I want to take my nice little control and add it to a greater control, maybe place some buttons around it etc. I could always inherit from it in a new custom control and dynamically add the buttons, but I thought about using a Web User Control. I thought I could easily create a Web User Control, drop on my grid and the buttons on a form, and expose some properties and events, but once I got into it, I got a feeling that this isn't what a Web User Control is for. When designing a control li...

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom User Controls v. Custom Web Controls
Hi! Is it better for me to begin coding my controls instead of just designing them? What would the benefits be? I meen, i seem to be able to get all i need from just putting stuff together on an ASCX file but i'm obviously missing a huge concept here... please explain! Hi, creating user controls is indeed easier than creating custom server controls because you can simply drag & drop other controls on the form, easily add events to it, ... Custom controls however are better when you want to reuse them in several other projects. I like to create custom controls for small, reusable com...

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...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET- http://www.aspnetzone.de/blogs/peterbuch...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

pass a control name to get uniquie control Id
I have many text boxes inside an AJAX TabContainer control and I would like the background of each textbox to change colors after the user has changed the text.  i know i will need code similar to document.getElementById('<%= txtBox1.ClientID %>').style.backgroundColor='red'; because when each textbox is rendered it is given a unique id.  I have a function that looks like this <script type="text/javascript">      function mkclr(ctrl) {        var control = document.getElementById...

Reusing custom web control in the same web control
Hello, I'm newbie in web development and of course asp.net. I am actually trying to build my first page and I'd like to know if it is possible to make a custom webcontrol that will contain itself. Let's say I want to draw a folder hierarchy in treeview-like structure. I thought I could make a control that will display a folder and if this folder contains subfolders then for each the control will include itself. Is this even possible? What would you suggest me to do to? Thanks in advance. TomTom Hagen http://thagen.dteam.info If the control can have child controls, then I s...

Web resources about - Web Custom Control - Create Control, Assign ID Name, ID Name Changes - asp.net.custom-server-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Church is about power, money and control
Readers react angrily, and sceptically, to the news that Cardinal George Pell may not be able to return to Australia to attend the royal commission ...

Microsoft Band updated to include music controls and inactivity alerts
... Microsoft Band came out, the company is adding functionality with a small software update. The two biggest features of this update—music controls ...

Control a car's features with a glance? Not science fiction
Filed under: Emerging Technologies , Infotainment , Technology Press a button to change your car's climate controls? Turn a knob to view your ...

"... Trump owns and controls the media... they can't not cover him... his audience is bigger than theirs ...
... their army (i.e., the media) can't take out their enemy. They don't have the slightest idea what to do.... The media, in their own minds, controls ...

How to control your iPhone by just tilting your head
... the best sight, hearing, or motor functions to still use iOS to its fullest capabilities — but they can also be used to customize your controls. ...

Jennifer Hudson On Gun Control: ‘We Are Acting Like Animals. We Need It’
Jennifer Hudson On Gun Control: ‘We Are Acting Like Animals.

Bart & Fleming: Don’t Come To Year-End Movies To Get Laid; Time For Movies About Gun Control Debate?
Peter Bart and Mike Fleming Jr. worked together for two decades at Daily Variety . In this weekly Sunday column, two old friends get together ...

The NFL Should Seize Control Of The Cleveland Browns
Drew Magary’s Thursday Afternoon NFL Dick Joke Jamboroo runs every Thursday during the NFL season. Email Drew here . Read more...

Republique finally gets analog controls on PS4
... transitions (like Resident Evil ) which is mildly disorienting at first but could actually be easier to wrap your head around with a controllable ...

Resources last updated: 12/14/2015 4:55:22 AM