Skip to main content

Posts

Showing posts with the label asp.net; control

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 , "

Set Page Programmatically

The page title in SharePoint is located in the content place holder called PlaceHolderPageTitle.   You can change it by referencing the place holder and setting a value in.   ContentPlaceHolder cp= (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitle"); cp.Controls.Clear(); cp.Controls.Add(new LiteralControl("The Title here"));   QED

Page Redirect in a sandbox

To redirect in a SharePoint sandbox is a nightmare. But don't panic, there is a way out. Create a literal control in your html as shown below:   < asp : Literal   ID = "litRedirect"   runat = "server"   /> and  in the codebehind do this:   litRedirect.Text =    string .Format( " " ,  string .Format( "{0}?k={1}" , thesearchresult, txtSearch.Value.Trim()));

Set Search Text Box Default

Ways to set search text box default is given below:   txtSearch.Value  =  "Search keywords" ;   txtSearch.Attributes.Add( "onfocus" ,  "if (this.value == 'Search keywords') this.value = '';" );   txtSearch.Attributes.Add( "onBlur" ,  "if (this.value == '') this.value = 'Search keywords';" );   this .Page.Form.DefaultButton = imgSearch.UniqueID;   Alternatively, you could wrap a panel control around your tags and set the default control on  that Panel.     < asp : Panel   ID = "pnlsearch"   runat = "server"   DefaultButton = "imgSearch" >                      < div   id = "search-drop" >                   ...