Search

just show me the code

Wednesday, May 27, 2009

forms authentication

...........

   38     <authentication mode="Forms">
   39       <forms loginUrl="~/Admin/Login.aspx" defaultUrl="~/Admin/Login.aspx"  protection="All" timeout="60"> 
   40         <credentials passwordFormat="Clear">
   41           <user name="ff" password="xxxxxx"/>
   42           <user name="someguy" password="xxxxxx"/>
   43         </credentials>
   44       </forms>
   45     </authentication>
   46     <authorization>
   47       <allow users="?/>
   48       <allow users="*">
   49     </authorization>

...........


  118   <location path="Public">
  119     <system.web>
  120       <authorization>
  121         <allow users="?"/>
  122       </authorization>
  123     </system.web>
  124   </location>
  125   <location path="Content">
  126     <system.web>
  127       <authorization>
  128         <allow users="?"/>
  129       </authorization>
  130     </system.web>
  131   </location>
  132   <location path="Admin">
  133     <system.web>
  134       <authorization>
  135         <allow users="ff"/>
  136         <deny users="*"/>
  137         <!--<allow users="?"/>-->
  138       </authorization>
  139     </system.web>
  140   </location>
  141   <location path="Admin/Login.aspx">
  142     <system.web>
  143       <authorization>
  144         <allow users="?"/>
  145       </authorization>
  146     </system.web>
  147   </location>


...........


   17
   18     protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
   19     {
   20         if (FormsAuthentication.Authenticate(this.Login1.UserName, this.Login1.Password))
   21             FormsAuthentication.RedirectFromLoginPage(this.Login1.UserName, true); 
   22     }




...........




Thanks to this link

Friday, May 22, 2009

powershell rename recurse

get-Childitem C:\Root\Dev\Drycode\Source * -recurse | rename-item -newName { $_.Name -replace 'XTempNameX', 'DryCode' } -whatif

(Get-Content C:\Root\Dev\Drycode\Source\NNNNNNNNN.txt) |
Foreach-Object {$_ -replace "NNNNNNNNN", "@@@@@@@@@@@@@@@@"} |
Set-Content C:\Root\Dev\Drycode\Source\NNNNNNNNN.txt -whatif

NNNNNNNNN.txt
asNNNNNNNNNdfasdf
saNNNNNNNNNdf
v fsda
faNNNNNNNNNsd
wefwef
sdfasNNNNNNNNN
vdafdsafasfas
NNNNNNNNN
NNNNNNNNN.txt after
as@@@@@@@@@@@@@@@@dfasdf
sa@@@@@@@@@@@@@@@@df
v fsda
fa@@@@@@@@@@@@@@@@sd
wefwef
sdfas@@@@@@@@@@@@@@@@
vdafdsafasfas
@@@@@@@@@@@@@@@@



foreach ($file in get-Childitem -recurse)
{
$file.directoryName + " " +$file.name + " " +$file.length
}


get-Childitem *NNNN* | get-member -membertype property


helpful links
link1
link2
link3
link4
link5
link6

Monday, May 18, 2009

Imports and Master Type in an aspx

here are your import and MasterType tags ...

    5 <%@ MasterType TypeName="DryCode.Web.Master.Site" %>
    6
    7 <%@ Import Namespace="DryCode.Web.Util" %>    
    8 <%@ Import Namespace="DryCode.Util" %>    

jquery ajax load

here is the content page (Load.aspx) ...

    6 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    7     <style>
    8         .otherPage{border:solid 1px black; background:#eee; margin:5px; padding:5px;}
    9     </style>
   10     <script language="javascript">
   11         $(document).ready(function() {
   12             LoadHtml();
   13         });
   14
   15         function LoadHtml() {
   16             $("#feeds").load("feeds.html");
   17         }
   18     </script>
   19 </asp:Content>
   20 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
   21     <span>this is in load.aspx</span>
   22     <div id="feeds" class="otherPage" ></div>
   23 </asp:Content>



here is the feeds.html



    2 <html xmlns="http://www.w3.org/1999/xhtml" >
    3 <head>
    4     <title></title>
    5 </head>
    6 <body>
    7     <div >
    8         <i>this is from feeds.html</i>
    9         <b>45</b> feeds found.
   10     </div>
   11 </body>
   12 </html>



the master page ....


     
    8     <script src="http://www.google.com/jsapi"></script>   
    9     <script type="text/javascript">  
   10
   11         // Load jQuery
   12         google.load("jquery", "1.3.2");
   13         google.load("jqueryui", "1.7.1");
   14         google.load("yui", "2.7.0");
   15
   16         google.setOnLoadCallback(function() {  
   17             // Your code goes here.  
   18         });  
   19     </script> 



result (Load.aspx) ...


this is in load.aspx


this is from feeds.html
45 feeds found.



Friday, May 15, 2009

jquery output

  184         <div id="output"></div>
 

  201     <script language="javascript">
  202         $(document).ready(function() { 
  203             $('.disclaimer').click(function() { 
  204                 $("#output").text($("#output").text() + "******* ");
  205             });
  206         });
  207     </script>

   41 </body>
   42 <script src="http://www.google.com/jsapi"></script>   
   43 <script type="text/javascript">   
   44     // Load jQuery 
   45     google.load("jquery", "1.3.2"); 
   46     //google.load("jqueryui", "1.7.1"); 
   47     //google.load("yui", "2.7.0"); 
   48     google.setOnLoadCallback(function() {  
   49         // Your code goes here.   
   50     });   
   51 </script> 
   52 <asp:ContentPlaceHolder ID="javascript" runat="server">
   53 </asp:ContentPlaceHolder>
   54 </html>

Thursday, May 14, 2009

send an array as a paramater


   17 protected void StartDateTextBox_TextChanged(object sender, EventArgs e)
   18 {
   19     this.DateRangeChanged();
   20 } 
   21 protected void EndDateTextBox_TextChanged(object sender, EventArgs e)
   22 {
   23     this.DateRangeChanged();
   24 }
   25 private void DateRangeChanged()
   26 {
   27     this.LoadOrdersDataSet();
   28     ListControl[] la = { this.lbParentBroker, this.lbClient, this.lbAccounts };
   29     this.ResetRebindControls(la);
   30 }
   31 protected void lbParentBroker_SelectedIndexChanged(object sender, EventArgs e)
   32 {
   33     ListControl[] la = { this.lbClient, this.lbAccounts };
   34     this.ResetRebindControls(la);
   35 }
   36 protected void lbClient_SelectedIndexChanged(object sender, EventArgs e)
   37 {
   38     ListControl[] la = { this.lbAccounts };
   39     this.ResetRebindControls(la);
   40 }
   41 protected void lbAccounts_SelectedIndexChanged(object sender, EventArgs e)
   42 {
   43     ListControl[] la = { };
   44     this.ResetRebindControls(la);
   45 }
   46 private void ResetRebindControls(ListControl[] lca)
   47 {
   48     this.SetVisiblePanel(PanelType.None);
   49     foreach (ListControl lc in lca)
   50         lc.SelectedIndex = -1;
   51     this.gvOrders.DataBind();
   52     foreach (ListControl lc in lca)
   53         lc.DataBind();
   54 }

Wednesday, May 13, 2009

Linq Filter by adding Where Clause


  187         public IQueryable<Talent> GetTalents(string searchExpression)
  188         {
  189             IQueryable<Talent> t;
  190             if (string.IsNullOrEmpty(searchExpression))
  191             {
  192                 t = _repository.GetTalents();
  193             } 
  194             else
  195             {
  196                 t = BasicSearch(searchExpression);
  197             }
  198             return t;
  199         }
  200
  201         private static readonly char[] SplitDelimiters = " ".ToCharArray();
  202
  203         // search should come in as  'jon johnny323@yahoo.com rodgers'
  204         private IQueryable<Talent> BasicSearch(string search)
  205         {
  206             // Just replacing "  " with " " wouldn't help with "a      b"
  207             string[] terms = search.Trim()
  208                                    .ToLower()
  209                                    .Split(SplitDelimiters,
  210                                           StringSplitOptions.RemoveEmptyEntries);
  211             IQueryable<Talent> talents = _repository.GetTalents();
  212             foreach (string s in terms)
  213             {
  214                 talents = AddBasicSearch(talents, s);
  215             }
  216             return talents;
  217         }
  218
  219         private IQueryable<Talent> AddBasicSearch(IQueryable<Talent> t, string s)
  220         {
  221             return t.Where(x =>  x.FirstName.ToLower().Contains(s)
  222                     || x.LastName.ToLower().Contains(s) 
  223                     || x.Email.ToLower().Contains(s) 
  224                     || x.LanguagesString.ToLower().Contains(s) 
  225                     );
  226         }

Tuesday, May 12, 2009

jquery validation

 
  127 <asp:Content ID="Content3" ContentPlaceHolderID="javascript" runat="server"> 
  128     <script type="text/javascript">
  129         $.validator.addMethod("lettersonly", function(value, element) {
  130             return this.optional(element)  /^[a-z]+$/i.test(value);
  131         }, "Letters only please");
  132
  133         $(document).ready(function() {
  134             $('form').validate({
  135                 errorLabelContainer: "#errorMessageBox"
  136                 , wrapper: "li"
  137                 , errorClass: "invalid"
  138                 //, submitHandler: function() { alert("Submitted!") }
  139             })
  140             $('#<%=FirstName.ClientID %>').rules("add", {
  141                 minlength: 2
  142                 , required: true
  143                 , lettersonly : true
  144                 , messages: {
  145                     minlength: jQuery.format("At least {0} characters are required for the first name")
  146                     , required: "First name is required"
  147                 }
  148             });
  149             $('#<%=LastName.ClientID %>').rules("add", {
  150                 minlength: 2
  151                 , required: true
  152                 , lettersonly: true
  153                 , messages: {
  154                     minlength: jQuery.format("At least {0} characters are required for the last name")
  155                     , required: "last name is required"
  156                 }
  157             });
  158         });
  159     </script>
  160 </asp:Content>


   19                 <div>
   20                     <ul id="errorMessageBox"></ul>
   21                 </div>
   22                 <div class="clear"></div>
   23                 <label>
   24                     <asp:Label ID="lblFirstName" runat="server"
   25                         Text="<%$ Resources:Resource,LabelFirstName%>"></asp:Label>
   26                 </label>
   27                 <asp:TextBox ID="FirstName" runat="server" class="normal" MaxLength="50"></asp:TextBox><br />
   28                 <label>
   29                     <asp:Label ID="lblLastName" runat="server"
   30                         Text="<%$ Resources:Resource,LabelLastName%>"></asp:Label>
   31                 </label>
   32                 <asp:TextBox ID="LastName" runat="server" class="normal" MaxLength="50"></asp:TextBox><br />


here is the css ...   


   95 /*validation part*/
   96 label.invalid { float: none; text-align: left; width: 100%; color:#ee3333; font-weight:normal; padding: 3px 0px; }
   97 input.invalid { background-color:#FFeeee; color:#ee3333; }
   98 select.invalid { background-color:#FFeeee; border:3px double #ff9999; color:#ee3333; }
   99 #errorMessageBox { margin-bottom: 15px;  }
  100 #errorMessageBox li { margin: 0px 40px 0px 40px; padding: 5px 20px; color:#ee3333; background: #FFeeee;
101 text-transform: none; list-style-type: disc; list-style-position: inside;}
  102 #errorMessageBox label { text-transform: none; }

Monday, May 11, 2009

Random Objects should be static

thanks to help from dotnetperls.

static Random _r = new Random();
static void F()
{
    // Use class-level Random so that when this
    // method is called many times, it still has
    // good Randoms.
    int n = _r.Next(12);
    // If this declared a local Random, it would
    // repeat itself.
    System.Console.WriteLine(n);
}

using jquery tips

http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx

tip #1

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>



http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js
http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.js

http://code.google.com/apis/ajaxlibs/documentation/index.html#jqueryUI

google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.1");
google.load("prototype", "1.6.0.3");
google.load("scriptaculous", "1.8.2");
google.load("mootools", "1.2.2");
google.load("dojo", "1.3.1");
google.load("swfobject", "2.1");
google.load("yui", "2.7.0");

Thursday, May 7, 2009

using System.Xml.Linq

using System.Xml.Linq;
protected void Button1_Click(object sender, EventArgs e)
{
  XDocument doc = new XDocument();
  XElement projectElement = new XElement("Project"
     , new XAttribute("ProjectName", "xxx")
     , new XAttribute("ProjectDescription", "xxx")
     , new XAttribute("DateStart", "xxx")
     , new XAttribute("DateEnd", "xxx") );
  doc.Add(projectElement);
  for (int i = 0; i < 5; i++)
  {
    projectElement.Add(new XElement("Property"
      , new XAttribute("PropertyName", "PropertyName" + i)
      , new XAttribute("PropertyValue", "PropertyValue" + i) ));
  }
  this.lbl.Text = Server.HtmlEncode(doc.ToString());
  this.lbl.DataBind();
}



will produce xml that looks like this




<Project ProjectName="xxx" ProjectDescription="xxx" DateStart="xxx" DateEnd="xxx" >
  <Property PropertyName="PropertyName0" PropertyValue="PropertyValue0" />
  <Property PropertyName="PropertyName1" PropertyValue="PropertyValue1" />
  <Property PropertyName="PropertyName2" PropertyValue="PropertyValue2" />
  <Property PropertyName="PropertyName3" PropertyValue="PropertyValue3" />
  <Property PropertyName="PropertyName4" PropertyValue="PropertyValue4" />
</Project>





 

Tuesday, May 5, 2009

popup and print

the javascript 
 
  136 <script language="javascript">
  137     $(document).ready(function() {
  138         $('#<%=Submit.ClientID %>').click( function() {
  139             popitup('../Public/PrintRegister.aspx');
  140             return true;
  141         }); 
  142     }); 
  143     function popitup(url) {
  144         newwindow = window.open(url, 'name', 'height=600,width=750');
  145         if (window.focus) { newwindow.focus() }
  146         return false;
  147     }
  148 </script>

the button


  110 <asp:ImageButton ID="Submit" runat="server" 
  111  ImageUrl="<%$ Resources:Resource,ImageSubmitPrint %>"
  112  AlternateText="<%$ Resources:Resource,ImageSubmitPrintAltText%>" 
  113  OnClick="Submit_Click" />

 


PrintRegister.aspx


    9 <body class="" onLoad="self.print()"> 
   10     <form id="form1" runat="server">
   11     <div>
   12       Print stuff here
   13     </div>
   14     </form>
   15 </body>

Contributors