Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

User Controls - naming conventions?

Posted on 2004-10-19
3
614 Views
Last Modified: 2012-06-27
Hi there,

Just started to create a user control and wondered if anybody can comment on naming conventions etc?

For my actual control I used  Pascal Casing and called it MainHeader

then when ever i insert this into a page it gives an automatic name of MainHeaderx where x is =1 , 2 or whatever..

What do people normally do here MainHeaderDefaultPage i.e. MainHeader (name of control) and afterwards add the page name?? or use an underscore ?? or just leave as 1,2,3 etc .. but this naming seems strange and unfriendly...

Any ideas or help would be really great

thanks

ian
0
Comment
Question by:ianinspain
  • 2
3 Comments
 

Author Comment

by:ianinspain
ID: 12345334
Oh and I forgot to mention, is it ok to put Javascript into a usercontrol, i am using an application called AllWebMenus which are basically some nice menus but they need to attach javascript where the menu is (usercontrol), i know best practises are to put the javascript in the head section of a webform, anyway to overide this .. i.e. force a move when page is built or should I just cut and past the javascript into the main webform under Head section?'

Ian
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 500 total points
ID: 12345548
Naming convention should be anything you feel comfortable with. But do please note that the INamingContainer (implemented by almost all WebControls) will change the resulting id of your object in the output. With usercontrols all I can say is that the name should reflect the object in such a way that you see the name and know what object you have.  

I would give my usercontrol a meaningful name, and whenever used on a page I would give the instance a meaningful id... or else it would come up as ctrlX with X being a number... makes things hard to distinguish.

Next question you have is how to add javascript to the header. The page object provides several functions to add javascript code to the page. For example (code copied from MSDN)

<html>
  <head>
     <script language="VB" runat="server">
    Sub Page_Load( sender as Object,e as EventArgs)
         
       'Form the script that is to be registered at client side.
        Dim scriptString as String = "<script language=JavaScript> function DoClick() {"
        scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<"
        scriptString += "/"
        scriptString += "script>"
     
            If(Not IsClientScriptBlockRegistered("clientScript"))
        RegisterClientScriptBlock("clientScript", scriptString)
        End If
     End Sub
     </script>
  </head>
  <body topmargin="20" leftmargin="10">
     <form id="myForm" runat="server">
        <input type="text" id="show" style="width=200">
      <input type="button" value="ClickMe" onclick="DoClick()">
     </form>
  </body>
</html>

But there are other functions to add script to the page. Here is an overview.

IsClientScriptBlockRegistered Determines if the client script block is registered with the page.
IsStartupScriptRegistered Determines if the client startup script is registered with the Page object.
RegisterArrayDeclaration Declares a value that is declared as an ECMAScript array declaration when the page renders.
RegisterClientScriptBlock Allows ASP.NET server controls to emit client-side script blocks in the Page.
RegisterOnSubmitStatement Allows a page to access the client OnSubmit event. The script should be a function call to client code registered elsewhere.
RegisterStartupScript Allows ASP.NET server controls to emit client-side script blocks in the Page.
0
 

Author Comment

by:ianinspain
ID: 12387255
Thanks CJ_S,

Thanks for the help, I have decided to name like this..

If my control is called "Header" then an instance on my default.aspx would be called

defaultHeader

Thanks for the script stuff too ... that was great,

Thanks - awarding points now

Ian
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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