Here is an example that dynamically adds some JavaScript onmouseout code for an image rollover:
imgImage.Attributes.Add("onmouseout", "src='" + ResolveUrl("~/Images/something_active.gif") + "'");
If ASP.NET, WCF, or Visual Studio has pissed me off, you're sure as hell going to hear about it here.
imgImage.Attributes.Add("onmouseout", "src='" + ResolveUrl("~/Images/something_active.gif") + "'");
cb = new CheckBox();
cb.AutoPostBack = true;
cb.CheckedChanged += new System.EventHandler(this.CB_CheckedChanged);
<asp:BoundField DataField="the_date" HeaderText="Date" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="false" />
StringBuilder sbValid = new StringBuilder();
sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sbValid.Append("if (Page_ClientValidate() == false) { return false; }} ");
sbValid.Append("this.value = 'Please Wait...';");
sbValid.Append("this.disabled = true;");
sbValid.Append("document.forms[0].ctl00_ContentPlaceHolder1_btnPaymentSubmit.disabled = true;");
sbValid.Append(this.Page.GetPostBackEventReference(this.btnPaymentSubmit));
sbValid.Append(";");
btnPaymentSubmit.Attributes.Add("onclick", sbValid.ToString());
private void ResetScrollPosition()
{
if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "CreateResetScrollPosition"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "CreateResetScrollPosition", "function ResetScrollPosition() {" + Environment.NewLine +
" var scrollX = document.getElementById('__SCROLLPOSITIONX');" +
Environment.NewLine + " var scrollY = document.getElementById('__SCROLLPOSITIONY');" +
Environment.NewLine + " if (scrollX && scrollY) {" +
Environment.NewLine + " scrollX.value = 0;" +
Environment.NewLine + " scrollY.value = 0;" +
Environment.NewLine + " }" +
Environment.NewLine + "}", true);
ClientScript.RegisterStartupScript(this.GetType(), "CallResetScrollPosition", "ResetScrollPosition();", true);
}
}