Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3317228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:33:47+00:00 2026-05-17T22:33:47+00:00

I am completly new in asp.net and I’m having some problems with it. I

  • 0

I am completly new in asp.net and I’m having some problems with it.
I created litle web form for demo and learning and I have some problems with it. Hopefuly you can help me 🙂

What I want is that:

  • when I click on “Kill X” button in table, I get “You pressed button Kill X” message in label “lblMsg”. I Also want that I get table with new data.
  • when I click “Load” button, I need to get additional rows in the table. For example now when page loads there is 10 rows in table and when I click “Load” I nedd to get additional 10 rows at the end into the same table.

P.S:
I would be grateful for some tutorial how to deal with events in asp.net.

Bellow is the code:

WebForm1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="HelpdeskOsControl.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
<asp:Panel ID="Panel1" runat="server" Height="465px" Width="417px">
    <asp:Table ID="Processes" runat="server" Height="20px" Width="400px" CssClass="tablesorter">
        <asp:TableHeaderRow ID="ProcessesHeader" runat="server" 
        TableSection="TableHeader">
            <asp:TableHeaderCell ID="TableHeaderCell1" runat="server">Name</asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell2" runat="server">CPU</asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell3" runat="server">Memory</asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell4" runat="server"></asp:TableHeaderCell>
        </asp:TableHeaderRow>
    </asp:Table>
    <asp:Panel ID="Panel2" runat="server">
        <asp:Button ID="btnLoad" runat="server" onclick="btnLoad_Click" Text="Load" />
        <asp:Button ID="btnClear" runat="server" onclick="btnClear_Click" 
            Text="Clear" />
        <asp:Label ID="lblMsg" runat="server" Text="Label"></asp:Label>
    </asp:Panel>
</asp:Panel>
    </form>
</body>
</html> 

WebForm1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HelpdeskOsControl
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                GenerateTable(getTestData());
        }

        private List<string> getTestData()
        {
            List<string> tData = new List<string>();
            Random rand = new Random();
            for (int i = 0; i < 10; i++)
            {
                tData.Add("proc" + i + "_" + rand.Next(100) + "_" + rand.Next(100));
            }

            return tData;
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            for (int i = Processes.Rows.Count; i > 1; i--)
            {
                Processes.Rows.RemoveAt(i - 1);
            }
        }

        protected void btnLoad_Click(object sender, EventArgs e)
        {
            GenerateTable(getTestData());
        }

        protected void btnKill_Click(object sender, EventArgs e)
        {
            lblMsg.Text = "You pressed button " + ((Button)sender).Text;
        }

        private void GenerateTable(List<string> list)
        {
            int st = 0;
            foreach (string line in list)
            {
                TableRow tr = new TableRow();
                Processes.Controls.Add(tr);

                foreach (String str in line.Split('_'))
                {
                    int index = tr.Cells.Add(new TableCell());
                    tr.Cells[index].Text = str;
                }

                Button b = new Button();
                b.Text = "Kill " + st;
                b.ID = "btnKill_" + st;
                b.Click += new EventHandler(btnKill_Click);
                TableCell tc = new TableCell();
                tc.Controls.Add(b);
                tr.Cells.Add(tc);

                tr.TableSection = TableRowSection.TableBody;
                st++;
            }
            Processes.BorderStyle = BorderStyle.Solid;
            Processes.GridLines = GridLines.Both;
            Processes.BorderWidth = 2;
        }

    }
}-
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:33:48+00:00Added an answer on May 17, 2026 at 10:33 pm

    I understand this is your first time with ASP.NET and want to help you learn more about its potentials.

    First of all, I would replace the code you wrote with data binding, which is a way to easily build tables without having to write methods like your generateTable. ASP.NET takes care of building the table by itself. It will take me a while to illustrate you full code for achieving this, but I hope you can grab the documentation and start learning with my help.

    The key control is GridView. It can be populated using a two-lines code fragment

    protected override OnLoad(EventArgs e)
    {
        if (!IsPostback) DataBind();
    }
    
    protected override void OnDataBind(EventArgs e)
    {
        gridView.DataSource = getTestData();
        gridView.DataBind();
    }
    

    You must first configure columns in layout. The articles about GridView deal with this, and you can add a button for each row.

    Now,

    you can set the buttons as command buttons, thus not only raising the Click event, but, more important, the Command event which takes a name and an argument. That’s where you can inject your code. For example

    <asp:Button id="btnSomething" CommandArgument="[procId]" CommandName="kill" OnCommand="myCommandHandler" />
    
    protected void myCommandHandler(object sender, CommandEventArgs e)
    {
        if (e.CommandName=="kill")
        {
            killProcess(e.CommandArgument);
            
            DataBind(); //MOST IMPORTANT
        }
    }
    

    Hope to have been of help. I wrote this code by hand, so please understand me if it will not work immediately

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems with my ASP.NET web forms system. It worked on our test
Completely new to asp.net mvc... completely new to web apps so bear with me...
I am completely new to ASP.Net MVC. I just created an MVC3 project in
I have extensive experience working in ASP.NET and Sql Server but I am new
I am new to ASP.NET MVC and I have a question regarding viewing entity
I have a hybrid ASP.Net web forms/MVC app. On one of the MVC pages/views,
I have worked with ASP.NET(C#, classic/MVC), Django(Python) and CI(php) but I am completely new
I have an API consisting of ASP.NET webservices callable through GET/POST/SOAP. A new functionality
I am a new guy in Asp.net. I have one requirement of doing one
can i have some general advice on converting a classic asp site to asp.net?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.