Solved

User Controls - naming conventions?

Posted on 2004-10-19
3
619 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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 …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

632 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