Hi, im having a problem with a custom control in asp.net
I've googled but I cant find any solution, maybe the people here can lend me a hand.
Here's the code
public Table generateControls(GeoData geodata)
{
Table table = new Table();
Label StrAddress = new Label();
Label Localty = new Label();
Label Country = new Label();
ImageButton Locate = new ImageButton();
ImageButton Accept = new ImageButton();
//Asigno los valores a los controles
Locate.ImageUrl = "/Img/icon-map.png";
Locate.ImageAlign = ImageAlign.AbsMiddle;
Locate.Height = 32;
Locate.Width = 32;
Locate.CommandArgument = System.Guid.NewGuid().ToString();
Locate.ID = System.Guid.NewGuid().ToString();
Locate.Click += new ImageClickEventHandler(Locate_Click);
Locate.PostBackUrl = "default.aspx";
Accept.ImageUrl = "/Img/big_green_tick_icon.png";
Accept.ImageAlign = ImageAlign.AbsMiddle;
Accept.Height = 32;
Accept.Width = 32;
string[] data = geodata.Address.Split(',');
if (data.Length == 5)
{
StrAddress.Text = "<b>Direccion:</b> " + data[0];
Localty.Text = "<b>Localidad:</b> " + data[1] + ", " + data[2] + ", " + data[3];
Country.Text = "<b>Pais:</b> " + data[4];
}
else if (data.Length == 4)
{
StrAddress.Text = "<b>Direccion:</b> " + data[0];
Localty.Text = "<b>Localidad:</b> " + data[1] + ", " + data[2];
Country.Text = "<b>Pais:</b> " + data[3];
}
else
{
StrAddress.Text = "<b>Direccion:</b> " + data[0];
Localty.Text = "<b>Localidad:</b> " + data[1];
Country.Text = "<b>Pais:</b> " + data[2];
}
TableRow firstRow = new TableRow();
TableCell firstCell = new TableCell();
TableCell locateButtonCell = new TableCell();
locateButtonCell.Controls.Add(Locate);
locateButtonCell.Width = 32;
firstCell.Controls.Add(StrAddress);
firstRow.Cells.Add(firstCell);
firstRow.Cells.Add(locateButtonCell);
TableRow seccondRow = new TableRow();
TableCell seccondCell = new TableCell();
seccondCell.Controls.Add(Localty);
seccondRow.Cells.Add(seccondCell);
TableRow thirdRow = new TableRow();
TableCell thirdCell = new TableCell();
TableCell acceptButtonCell = new TableCell();
acceptButtonCell.Controls.Add(Accept);
acceptButtonCell.Width = 32;
thirdCell.Controls.Add(Country);
thirdRow.Cells.Add(thirdCell);
thirdRow.Cells.Add(acceptButtonCell);
table.Rows.Add(firstRow);
table.Rows.Add(seccondRow);
table.Rows.Add(thirdRow);
table.BorderWidth = 1;
table.Width = 280;
return table;
}
protected void Locate_Click(object sender, EventArgs e)
{
onLocateClick(e);
}
protected virtual void onLocateClick(EventArgs e)
{
if (locateClick != null)
{
locateClick(this, e);
}
}
And here's the control being used in the main page
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GeoData geodata in GoogleGeocoder.GetGeoList(this.TextBox1.Text, true))
{
GeoLocationResulto gs = new GeoLocationResulto();
gs.locateClick += new EventHandler(locateOnMap);
this.Panel1.Controls.Add(gs.generateControls(geodata));
}
geoLocationControl.Update();
}
protected void locateOnMap(object sender, EventArgs e)
{
Button1.Text = "foo";
}
when the button is clicked, the control shows up, but, upon clicking the button that should fire "locateOnMap", the whole page is reloaded instead of the expected behavior.