B
Bob Cummings
Greetings
I have figured out how to create my own WebCustomControl and use it on a
web form. It is a very simple control, a couple of labels and a button.
I have been able to create and raise a custom event handler for the
button. That is the web form as a private method in the "code behind"
page and I can invoke that method when clicking on the button in my
WebCustomControl.
I can read my data from the database and put the information in the
correct places. And all is good so far.
However the problem I am running across is when I create the custom
controls on the fly so to speak how can I capture the button click event
from one of them and how will I know which one it is?
Here is how I am adding them to the page, I needed to add them to a
panel for otherwise they went all over and panel contains them nicely.
private void buildPage()
{
try
{
OleDbDataReader dr ;
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText="SELECT Title, Author, Media, Year, Available FROM
resource";
if (myCon.State == ConnectionState.Closed) myCon.Open();
cmd.Connection = myCon;
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while(dr.Read())
{
myDisplay = new CustomControl.Display();
myDisplay.Title = dr.GetString(0);
myDisplay.Author = dr.GetString(1);
myDisplay.Media = dr.GetString(2);
myDisplay.Year = dr.GetString(3);
myDisplay.Available = dr.GetBoolean(4).ToString();
this.myGrid1.Controls.Add(myDisplay);
}
}
catch (System.Exception e)
{
Response.Write (e.Message);
myCon.Close();
}
}
}
And this event handler worked fine when I only read in one column but
now there may be 100 of them and I am lost how to handle that situation.
public void myDisplay_Click (object sender, System.EventArgs e)
{
CustomControl.Display my = (CustomControl.Display)sender;
Response.Write(my.UniqueID.ToString());
}
thanks
Bob
I have figured out how to create my own WebCustomControl and use it on a
web form. It is a very simple control, a couple of labels and a button.
I have been able to create and raise a custom event handler for the
button. That is the web form as a private method in the "code behind"
page and I can invoke that method when clicking on the button in my
WebCustomControl.
I can read my data from the database and put the information in the
correct places. And all is good so far.
However the problem I am running across is when I create the custom
controls on the fly so to speak how can I capture the button click event
from one of them and how will I know which one it is?
Here is how I am adding them to the page, I needed to add them to a
panel for otherwise they went all over and panel contains them nicely.
private void buildPage()
{
try
{
OleDbDataReader dr ;
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText="SELECT Title, Author, Media, Year, Available FROM
resource";
if (myCon.State == ConnectionState.Closed) myCon.Open();
cmd.Connection = myCon;
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while(dr.Read())
{
myDisplay = new CustomControl.Display();
myDisplay.Title = dr.GetString(0);
myDisplay.Author = dr.GetString(1);
myDisplay.Media = dr.GetString(2);
myDisplay.Year = dr.GetString(3);
myDisplay.Available = dr.GetBoolean(4).ToString();
this.myGrid1.Controls.Add(myDisplay);
}
}
catch (System.Exception e)
{
Response.Write (e.Message);
myCon.Close();
}
}
}
And this event handler worked fine when I only read in one column but
now there may be 100 of them and I am lost how to handle that situation.
public void myDisplay_Click (object sender, System.EventArgs e)
{
CustomControl.Display my = (CustomControl.Display)sender;
Response.Write(my.UniqueID.ToString());
}
thanks
Bob