Friday, December 2, 2011

how to create dynamic table in asp.net


How to create dynamic table in asp.net 3.5
Why the LoadViewState()?
When the controls are added to page, it is done quiet early in the page event cycle. Hence the LoadViewState() gives you an ideal placeholder to recreate the controls. Since the LoadViewState() method is called before the Page_Load() event, re-adding controls in this method assures that the controls can be access and manipulated by the time any event occurs on them.
Step 1: Create a new ASP.NET application. Add two textboxes (txtRows and txtCols) and a button (btnGenerate) control to the page. The two textboxes will accept the number of Rows and Columns from the user. Based on the input in the textboxes, the table will be created dynamically on the button click. Also add a container element (to position the table) and a button (btnPost) to cause a postback the second time, once the table data is manipulated.
The mark up will look similar to the following:
<body>
    <form id="form1" runat="server">
    <div>
    <div>
        Rows: <asp:TextBox ID="txtRows" runat="server" Width="30px"> </asp:TextBox> <br />
        Cols: &nbsp;<asp:TextBox ID="txtCols" runat="server" Width="30px"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="btnGenerate" OnClick="btnGenerate_Click" runat="server" Text="Generate" />&nbsp;<br /> <br />
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        <br />
        <br />
    </div>
    </div>
        <asp:Button ID="btnPost" runat="server" OnClick="Button1_Click" Text="Cause Postback" />
    </form>
</body>

Step 2: The number of rows and columns for the table is to be taken from the user. For this purpose, we will accept the values in the Page_Load() event. We will create properties for both the rows and columns and store in the ViewState so that the data is available on the postback.
C#
// Rows property to hold the Rows in the ViewState
    protected int Rows
    {
        get
        {

Thursday, September 15, 2011

Add Rotator Control In Asp.Net



How to use add rotator
protected System.Web.UI.WebControls.AdRotator AdRotator;
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;

Namespaces used in this application:

using System.Web.UI.WebControls;
using System.Drawing;
using System.Web.UI.HtmlControls;

Add a Xml File
// XML CODE THAT AS THE DETAILS ABOUT THE ADS
<Advertisements>
    <Ad>
        <ImageUrl>D:\Viv_B-Practice\AdRotator_VT\www.asp.net.gif</ImageUrl>
        <NavigateUrl>http://www.asp.net</NavigateUrl>
        <AlternateText>ASP.NET Logo</AlternateText>
        <Keyword>A</Keyword>
        <Impressions>Technology</Impressions>
        <Caption>This is the caption for Ad#1</Caption>
    </Ad>

    <Ad>
        <ImageUrl>D:\Viv_B-Practice\AdRotator_VT\www.sulekha.com.gif</ImageUrl>
        <NavigateUrl>http://www.sulekha.net</NavigateUrl>
        <AlternateText>www.Sulekha.net</AlternateText>
        <Keyword>S</Keyword>
        <Impressions>Web Site</Impressions>
        <Caption>This is the caption for Ad#2</Caption>
    </Ad>

    <Ad>
        <ImageUrl>D:\Viv_B-Practice\AdRotator_VT\FlashFile.swf</ImageUrl>
        <NavigateUrl>AdRotator.aspx?ad=Widgets
               &target=http://msdn.microsoft.com/widgets/</NavigateUrl>
        <AlternateText>www.neostream.net</AlternateText>
        <Keyword>S</Keyword>
        <Impressions>Flash Site</Impressions>
        <Caption>This is the caption for Ad#2</Caption>
    </Ad>
</Advertisements>

The above shown is the XML code. The above XML template contains the details about each ad that is going to be placed in the web application. You can create an ad list for the AdRotator control in the XML designer using the Ad Rotator Schedule File as the target schema.

The AdRotator Properties

ImageUrl - The URL of the image to display.
NavigateUrl - The URL of the page to navigate to when the AdRotator control is clicked.
AlternateText - The text to display if the image is unavailable.
Keyword - The category of the ad that can be used to filter for specific ads.
Impressions - A numeric value that indicates the likelihood of how often the ad is displayed. The total of all impression values in the XML file may not exceed 2,048,000,000 - 1. All attributes are optional.

The AdRotator Class

Basically, the actual AdRotator class only provides a limited set of properties:

<asp:AdRotator id="controlName" runat="server"
    AdvertisementFile="ads.xml" Target="_self">
</asp:AdRotator>

Here we can see how a placeholder control creates the ad rotator control at runtime dynamically and how it works. The PlaceHolder control enables you to place an empty container control in the page and then dynamically add child elements to it at run time.

// Create an AdRotator control.

AdRotator rotator = new AdRotator();

// Set the control's properties.

rotator.AdvertisementFile = "AdRotatorFiles.xml";

// Add the control to the Controls collection of a

// PlaceHolder control. 

PlaceHolder1.Controls.Add(rotator);

The PlaceHolder web server control enables you to place an empty container control within the page and then dynamically add, remove, or loop through child elements at run time. The control only renders its child elements; it has no HTML-based output of its own. As an example, you might want to have a variable number of buttons appear on a web page, depending on options selected by users. That way, users are not confronted with potentially confusing choices that are either unavailable or not relevant to their individual needs.


Friday, August 26, 2011

Caleder Control Of Ajax


asp:TextBox and ajaxToolkit:CalendarExtender, so the page should be look like:
<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <title>Untitled Page</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1"runat="server" />
      <div>
        <asp:TextBox ID="Date1" runat="server"></asp:TextBox>
        <ajaxToolkit:CalendarExtender
            ID="CalendarExtender1" runat="server"TargetControlID="Date1">
        </ajaxToolkit:CalendarExtender>
      </div>
    </form>
  </body>
</html>
Note that TergetControlID point to the text box id.


Thursday, August 4, 2011

ASP.NET login page with sql server


First we have to create a database for storing the login information

Open the Sqlserver Management studio

Create a new database and change the database name as db_Logininformation
Create a New table in that database(db_Logininformation) and change the table name as tab_userinformation

Now, create the following fields
1.  UserID   int         PrimaryKey  
2.    
3.  username varchar(50)  
4.    
5.  Password varchar(50)  

Next, Enter the some usernames and paasword directlu in the database for checking purpose

and save the table

Next ,open the Microsoft visual studio 2008

Next,select the Aspnet web application and change the name as LoginPage

Next,come to the design page of LoginPage and drag and drop two labels,two textboxes and button

next,come to the code page of the Login.aspx.cs

Write the following codein the page event

1.  protected void Button1_Click(object sender, EventArgs e)  
2.      {        
3.          con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ToString());  
4.          con.Open();  
5.          com = new SqlCommand("select Password from userinformation where Username='" + txt_uname.Text + "'", con);  
6.          dr = com.ExecuteReader();  
7.          if (!dr.Read())  
8.          {  
9.              Response.write("Invalid User");  
10.         }  
11.         else  
12.         {  
13.             if (dr[0].ToString() == txt_pwd.Text)  
14.             {  
15.                 Response.Redirect("~/mainPage.aspx");  
16.             }  
17.             else  
18.             {  
19.                Response.write("Wrong Password");  
20.                txt_pwd.Focus();  
21.             }  
22.         }  
23.   
24.     }  
finally,Execute the page....Thats it...Happy coding

Thursday, July 28, 2011

Need Marketing Executive

Golden Opportunity for freshers.....

A company need a person who must have good communication skills and good links in engineering  colleges.
if any body has both qualities then he will get good package as well as good designation.it is golden opportunity.
freshers can also apply.first preference will be given to Freshers..

Eligibility: Graduate or Post Graduate
Work Place: New Delhi

For Further Details:Contact on gulshan.arora.1986@gmail.com

Wednesday, July 27, 2011

delegates and events ...


//check  which key is pressed nice program...check this out............... 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace delegates_and_events
{
    // This example demonstrates:
    // the Console.CancelKeyPress event,
    // the ConsoleCancelEventHandler delegate,
    // the ConsoleCancelEventArgs.SpecialKey property, and
    // the ConsoleCancelEventArgs.Cancel property.

 

    class Sample
    {
        public static void Main()
        {
            ConsoleKeyInfo cki;

            // Clear the screen.
            Console.Clear();

            // Turn off the default system behavior when CTRL+C is pressed. When
            // Console.TreatControlCAsInput is false, CTRL+C is treated as an
            // interrupt instead of as input.
            Console.TreatControlCAsInput = false;

            // Establish an event handler to process key press events.
            Console.CancelKeyPress += new ConsoleCancelEventHandler(myHandler);
            while (true)
            {
                // Prompt the user.
                Console.Write("Press any key, or 'X' to quit, or ");
                Console.WriteLine("CTRL+C to interrupt the read operation:");

                // Start a console read operation. Do not display the input.
                cki = Console.ReadKey(true);

                // Announce the name of the key that was pressed .
                Console.WriteLine("  Key pressed: {0}\n", cki.Key);

                // Exit if the user pressed the 'X' key.
                if (cki.Key == ConsoleKey.X) break;
            }
        }

        /*
           When you press CTRL+C, the read operation is interrupted and the
           console cancel event handler, myHandler, is invoked. Upon entry
           to the event handler, the Cancel property is false, which means
           the current process will terminate when the event handler terminates.
           However, the event handler sets the Cancel property to true, which
           means the process will not terminate and the read operation will resume.
        */
        protected static void myHandler(object sender, ConsoleCancelEventArgs args)
        {
            // Announce that the event handler has been invoked.
            Console.WriteLine("\nThe read operation has been interrupted.");

            // Announce which key combination was pressed.
            Console.WriteLine("  Key pressed: {0}", args.SpecialKey);

            // Announce the initial value of the Cancel property.
            Console.WriteLine("  Cancel property: {0}", args.Cancel);

            // Set the Cancel property to true to prevent the process from terminating.
            Console.WriteLine("Setting the Cancel property to true...");
            args.Cancel = true;

            // Announce the new value of the Cancel property.
            Console.WriteLine("  Cancel property: {0}", args.Cancel);
            Console.WriteLine("The read operation will resume...\n");
        }
    }
    /*
    This code example produces results similar to the following text:

    Press any key, or 'X' to quit, or CTRL+C to interrupt the read operation:
      Key pressed: J

    Press any key, or 'X' to quit, or CTRL+C to interrupt the read operation:
      Key pressed: Enter

    Press any key, or 'X' to quit, or CTRL+C to interrupt the read operation:

    The read operation has been interrupted.
      Key pressed: ControlC
      Cancel property: False
    Setting the Cancel property to true...
      Cancel property: True
    The read operation will resume...

      Key pressed: Q

    Press any key, or 'X' to quit, or CTRL+C to interrupt the read operation:
      Key pressed: X

    */
}

AngularJS Basics - Part 1

                                                                  AngularJS What is AngularJS ·          Framework by googl...