September 2004 - Posts

Dear Developer..now you can register User Controls Globally (ASP.NET 2.0)

In ASP.Net 1.x, if you wanted to use any user control, you need to add a page directive (for .ascx) in that .aspx page. Let's say, if you wanted to use in most of the pages, then it's going to be hard as you need to add the directive in most of the pages!


But in ASP.Net 2.0, you can define this at the web.config level. Once you define in web.config, you can use it in entire project.

 

Example syntax in web.config would be as showin below:
<pages>
      
<controls>
            
<add tagPrefix="MenuUCTL" tagName="MenuControl" src="~/MenuControl.ascx" />
      
</controls >
</pages >
</system.web>


Another good thing is, once you add in web.config, you are going to start seeing intelliSense for that control in VS.NET and it’ going to make your life easy in using that control :)

Here is an example picture showing intelliSense for control in VS.NET!



user control intellisense image in vs.net asp.net2.0

 

J Hoping this new feature exites you  J

Posted by SreedharK with 11 comment(s)

Take advantage of DefaultButton property in ASP.NET 2.0

If you are new to ASP.NET 2.0, then this would be good news to you! If you have more than one button on a form and if you wanted to keep a specific button as default one, then the DefaultButton property helps you to specify any button on a form as the default button when the form loads.
(For a new commer to the web development, the default button is the button which will post back to the server if you press the ENTER key)

 

For example, if you wanted to specify SubmitButton as a default button, then the syntax would be as shown below.

<form id="Form1"

    defaultbutton="SubmitButton"

    defaultfocus="TextBox1"

    runat="server">

 

Complete example:

<%@ page language="C#" %>

 

<html>

<head>

  <script runat="Server">    

  

    void Page_Load(object sender, System.EventArgs e)

    {

      Label1.Text = "The DefaultButton property is set to "

                    + Form1.DefaultButton.ToString() + "<br/>";

      Label2.Text = "The DefaultFocus property is set to "

                    + Form1.DefaultFocus.ToString();

     }

 

      void CancelButton_Click(object sender, EventArgs e)

      {

          Response.Write("Cancle is clicked");

      }

</script>

</head>

<body>

  <form id="Form1"

    defaultbutton="SubmitButton"

    defaultfocus="TextBox1"

    runat="server">

   

    <h3>DefaultButton and DefaultFocus Properties Example (2.0)</h3>        

 

    TextBox1:

    <asp:textbox id="TextBox1"

      autopostback="true"

      runat="server">

    </asp:textbox>

 

    <br />

 

    TextBox2:

    <asp:textbox id="TextBox2"

      autopostback="true"

      runat="server">

    </asp:textbox>

 

    <br /><br />

 

    <asp:button id="SubmitButton"

      text="Submit"

      runat="server">

    </asp:button>

 

    <asp:button id="CancelButton"

      text="Cancel"

      runat="server" OnClick="CancelButton_Click">

    </asp:button>

 

    <hr />

 

    <asp:label id="Label1"

      runat="Server">

    </asp:label>

 

    <asp:label id="Label2"

      runat="Server">

    </asp:label>

 

  </form>

</body>

</html>

 

Hope it helps you!

Posted by SreedharK with 56 comment(s)
More Posts