Mark,
Here is a sample page that adds a button dynamically and handles its click event:
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
private void Page_Load(object sender, System.EventArgs e)
{
HtmlInputButton button = new HtmlInputButton();
button.Value = "Generated Button";
button.ServerClick += new EventHandler(this.GeneratedButton_Click);
PlaceHolder1.Controls.Add(button);
}
public void GeneratedButton_Click(object source, EventArgs e)
{
Response.Write("DONE");
}
}
Tu-Thach
----- Mark wrote: -----
Any ideas on how to deal with a control that is created on the fly to add
onclick event??
I know i can add a button to the grid, but would like to get avoid that if
possible
Thanks
"Tu-Thach" <tu*****@ongtech.com> wrote in message
news:78**********************************@microsof t.com...
Mark, Your GetImage method is a server-side method and you are trying to add the
onclick attribute on the image, which is a client-side method. That's why
it is not working. Tu-Thach
----- Mark wrote: -----
Hello Ok, I have this datagrid an in the itemdatabound sub I have this
code strTemp = _strProgressImagesURL & e.Item.Cells(2).Text &> ".jpg?e=2&w=105&h=70"
_myImage = New System.Web.UI.WebControls.Image _myImage.ImageUrl = strTemp
_myImage.BorderStyle = BorderStyle.Inset
_myImage.BorderWidth = Unit.Pixel(5)
_myImage.ID = "img" & e.Item.Cells(0).Text
e.Item.Cells(2).Text = ""
_myImage.Attributes.Add("onclick", "GetImage()")
e.Item.Cells(2).Controls.Add(_myImage)
Now everything works fine except i cant get the attribute to work.
on the aspx file I have this just to tell me its working<script language=vb runat=server>>> sub GetImage(sender as object,e as eventargs)
response.write "Made it"
end sub But it dont work. Help please
Thansk
>>>>>>>>>