Skip to main content

Posts

Showing posts with the label client

Register client side scripts in code behind

Quick way to register client side scripts.     Let us take the css files first: CssLink cssLink = new CssLink (); cssLink . DefaultUrl = "/_layouts/appname/cssfiletoregister.css" ; this . Page . Header . Controls . Add ( cssLink );     string scriptPath = "/_layouts/appname/jstoregister.js" ; if (! this . Page . ClientScript . IsClientScriptBlockRegistered ( scriptPath )) this . Page . ClientScript . RegisterClientScriptBlock ( this . GetType (), scriptPath , "

Create a jQuery alert programmatically

From the code behind:   Assuming you have jquery on your page already.   StringBuilder  strScriptFeatured =  new   StringBuilder (); strScriptFeatured.Append( "$(document).ready(function(){" ); strScriptFeatured.Append( "alert('Your alert here!');" ); strScriptFeatured.Append( "});" ); Page.ClientScript.RegisterStartupScript( this .GetType(),  "Script" , strScriptFeatured.ToString(),  true );   QED  

Add single/double click to gridview

protected void grdClickDoubleClick_RowDataBound(object sender, GridViewRowEventArgs e) { try { GridViewRow row = e.Row; if (row.RowType == DataControlRowType.DataRow) { ImageButton _singleClickButton = row.FindControl("lnkBtnClk") as ImageButton; string _jsSingleClick = Page.ClientScript.GetPostBackClientHyperlink(_singleClickButton, ""); e.Row.Attributes.Add("onclick", _jsSingleClick); ImageButton _dblClickButton = row.FindControl("lnkBtnClk") as ImageButton; string _jsDoubleClick = Page.ClientScript.GetPostBackClientHyperlink(_dblClickButton, ""); e.Row.Attributes.Add("ondblclick", _jsDoubleClick); } } catch (Exception ex) { } }