Solved

User Controls - naming conventions?

Posted on 2004-10-19
3
617 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
[X]
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
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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