Hi, I have a custom control, and one of my child controls that I want is an image button. If I do a regular input btn:
System.Web.UI.HtmlControls.HtmlInputButton, then I can run a javascript function directly:
System.Web.UI.HtmlControls.HtmlInputButton hSaveBtn = new System.Web.UI.HtmlControls.HtmlInputButton (); hSaveBtn.ID = "saveBtn"; hSaveBtn.Name = "saveBtn"; hSaveBtn.Value = "save"; hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny();" );
And it doesn't do a postback ( it works correctly )
But interestingly enough if I have an Image button, it causes a postback, which really screws things up.
System.Web.UI.HtmlControls.HtmlInputImage hSaveBtn = new System.Web.UI.HtmlControls.HtmlInputImage(); hSaveBtn.ID = "saveBtn"; hSaveBtn.Name = "saveBtn"; hSaveBtn.Src = "~/OMWAImages/Crystal_Clear_action_apply.png"; hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny();" );
Any hints?
you need to prevent the default action from occurring, you can do this by appending return false to the onclick code
hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny(); return false;" );
Log in to post a comment.
Hi, I have a custom control, and one of my child controls that I want is an image button. If I do a regular input btn:
System.Web.UI.HtmlControls.HtmlInputButton, then I can run a javascript function directly:
System.Web.UI.HtmlControls.HtmlInputButton hSaveBtn = new System.Web.UI.HtmlControls.HtmlInputButton ();
hSaveBtn.ID = "saveBtn";
hSaveBtn.Name = "saveBtn";
hSaveBtn.Value = "save";
hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny();" );
And it doesn't do a postback ( it works correctly )
But interestingly enough if I have an Image button, it causes a postback, which really screws things up.
System.Web.UI.HtmlControls.HtmlInputImage hSaveBtn = new System.Web.UI.HtmlControls.HtmlInputImage();
hSaveBtn.ID = "saveBtn";
hSaveBtn.Name = "saveBtn";
hSaveBtn.Src = "~/OMWAImages/Crystal_Clear_action_apply.png";
hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny();" );
Any hints?
you need to prevent the default action from occurring, you can do this by appending return false to the onclick code
hSaveBtn.Attributes.Add ( "onclick", ID + @"InPlace.saveTiny(); return false;" );