Solved

Getiing info from HTML components

Posted on 2004-08-24
6
162 Views
Last Modified: 2010-04-15
Hi All,

I have a ASPX page with a <div> and a <panel>.

In my code I gegerate a table on the fly and place it inside the panel.

The table has check boxes in it and there is javascript to handle the turning of checkboxes on and off ...

I now want to know if when I press an <asp:button> how do I get the state of which of the check boxes were pressed.

I also need to know, if I decide im y C# code to change the boxes that were checked, how do I send that info back to the page ...

Txs
Peter
0
Comment
Question by:Pete2003
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
nhewitt21 earned 500 total points
ID: 11882988
code that goes in datagrid to make checkbox:
<ItemTemplate>
      <asp:Label id="DeleteCheckBox" text='<%#"<input class=\"search\" type=\"checkbox\" name=\"DeleteCB" + (DataBinder.Eval(Container.DataItem,"ID").ToString()) + "\" value=\"" + (DataBinder.Eval(Container.DataItem,"ID").ToString()) + "\"/>"%>' runat="server" /></ItemTemplate>

i have an input button:
<input id="DelSelected" name="DelSelected" runat="server">

in my codebehind:
private void DelSelected_ServerClick(object sender, System.Web.UI.ImageClickEventArgs e)
{
      foreach (string var in Request.Form)
      {
            if (var.IndexOf("DeleteCB") > -1)
            {
                  //calls function that removes item from database (via id)                  
                  DeleteFromPhotoAlbum(Convert.ToInt32(Request.Form[var].ToString()));

thats how i did it, there a bit more code
            }
      }
}

That works ok.
hope it helps you out.
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11883028
private void DelSelected_ServerClick(object sender, System.Web.UI.ImageClickEventArgs e)
{
     foreach (string var in Request.Form)
     {
          if (var.IndexOf("DeleteCB") > -1)
          {
               //calls function that removes item from database (via id)              
               DeleteFromPhotoAlbum(Convert.ToInt32(Request.Form[var].ToString()));
          }
     }
}
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11883081
and this:
this.DelSelected.ServerClick += new System.Web.UI.ImageClickEventHandler(this.DelSelected_ServerClick);

needs to go inside the InitializeComponent() for the OnInit
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Pete2003
ID: 11889919
Hi,

Thanks for the info I'm however lost right at the beginning .. what is the <itemTemplate> stuff ??

The way I did my table is just simple generation within a <panel> ...

0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11890113
ahh, i have misunderstood what you was trying to do.  I had assumed you was using a datagrid.  My bad, sorry.

The item template just creates a template column in the datagrid and puts checkboxexs in each row.  If your using a table then forget the template bit and the rest of the code should be enough for you to do what you need to do.
0
 

Author Comment

by:Pete2003
ID: 11892768
Ok I am really trying hard to understand how you are working this, but to no avail ...

There is no relevant data in the Request.Form as the table is in a panel which does not even appear in the form ...

Here is my ASPX page:

<DIV style="WIDTH: 791px; POSITION: relative; HEIGHT: 140px" ms_positioning="GridLayout"
      id="div1" runat="server">&nbsp;
      <asp:panel id="tablePanel" style="Z-INDEX: 102; LEFT: 0px; OVERFLOW: auto; POSITION: relative"
            Height="200px" Width="100%" Runat="server"></asp:panel>
</DIV>

I now use my codebehind to populate the tablePanel with a LiteralControl containing the HTML Table:
ie:

string sHTML = "<table><tr><td>Hello</td><td>Hello</td></tr></table>";
tablePanel.Controls.Add(new LiteralControl(sHTML));

Now I need to be able to access the "Hello" and "World" from my C# code ...

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

912 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now