studio NETSOULS

Applying Web To Your Business

A lot of times in development scenarios you come to a situation where you want to do a postback on a webpage when a user hits the enter button.

If you are using RadAjaxManager on that page, then to submit the page for postback or invoke a button click event handler, use the following code:

   1: function PerformPostBack(e)
   2: {
   3:     evt = e || window.event;
   4:     var Key = evt.which || evt.keyCode;
   5:     if ( Key == 13 ) 
   6:     {
   7:         AjaxNS.ARWO(new WebForm_PostBackOptions("<%=btnButton.UniqueID%>", "", true, "", "", false, true), "<%=UpdateControl.ClientID%>", event);
   8:         return false;
   9:     }
  10: }

In the web page where the textbox is set onKeyPress=”return PerformPostBack(event)”

  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

I am always searching the internet for the DateTime formats, so i thought i will post it in my blog so that i don’t need to keep googling for it.

Specifier String Result Output
d dd-MM-yyyy 03-01-2009
D dd MMMM yyyy 03 January 2009
f dd MMMM yyyy HH:mm:ss 03 January 2009 17:31:14
g MM/dd/yyyy HH:mm 03-01-2009 17:31:14
m MMMM dd January 03
r ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Sat, 03 Jan 2009 17:31:14 GMT
s yyyy'-'MM'-'dd'T'HH':'mm':'ss 2009-01-03T17:31:14
t HH:mm:ss 17:31:14
u yyyy'-'MM'-'dd HH':'mm':'ss'Z' 2009-01-03 17:31:14Z
U dd MMMM yyyy HH:mm:ss 03 January 2009 12:01:14
y MMMM, yyyy January, 2009
o yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2009-01-03T17:31:14.0303453+05:30
DateTime todayDate = DateTime.Now;
string dateToStringInFormat = todayDate.ToString(formatSpecifier, 
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

I would like to set the a property value on a user control. It sounds easy enough. First, I would like to create a web control then I would like to access one of its properties "HasAccess" and set the value to "true".

In this example we are assuming that the web control is been called from a master page and the property that needs to be set is from a web page. In the web page we need to first find the user control and then set its property.

   1: if (Master != null)
   2: {
   3:     Control ctlMyControl = Master.FindControl("ctlMyControl") as Control;
   4:     if (ctlMyControl != null)
   5:     {
   6:         Type ucType = null;
   7:         ucType = ctlMyControl .GetType();
   8:  
   9:         PropertyInfo hasAccess = ucType.GetProperty("HasAccess");
  10:  
  11:         // Only set the first control as each on page will pass through code. 
  12:         if (hasAccess.GetValue(ctlMyControl , null) == null)
  13:             hasAccess.SetValue(ctlMyControl , True, null);
  14:     }
  15: }
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

This example is useful when you need to add new row in the gridview. Here  to can add the link URL runtime.

Add a placeholder in the HTML page.

   1: <asp:PlaceHolder ID="phGrid" runat="server"></asp:PlaceHolder>

Now create the gridview run time

   1: private void BindGrid()
   2:   {
   3:     // Create new instance of gridview
   4:       GridView gvNew = new GridView();
   5:       gvNew.ID = "ItemGrid";
   6:       gvNew.SkinID = "ListView";
   7:       gvNew.Width = 300;
   8:  
   9:       DataTable dt = Datasource();
  10:       if (dt.Columns.Count > 1)
  11:       {
  12:             // Assign RowDataBound handler. This will add link URL dynamically.
  13:           gvNew.RowDataBound += new GridViewRowEventHandler(gvNew_RowDataBound);
  14:           gvNew.DataSource = dt;
  15:           gvNew.DataBind();
  16:       }
  17:       else
  18:       {
  19:             // Some Comments
  20:       }
  21:      
  22:       phGrid.Controls.Add(gvNew);
  23:  
  24:   }
   1: protected void gvNew_RowDataBound(object sender, GridViewRowEventArgs e)
   2:  {
   3:      int random = 1;
   4:      int count = e.Row.Cells.Count;
   5:  
   6:      if (e.Row.RowType == DataControlRowType.DataRow)
   7:      {
   8:          string str = e.Row.Cells[0].Text;
   9:      }
  10:      else if (e.Row.RowType == DataControlRowType.Footer)
  11:      {
  12:  
  13:          Label lblEdit = new Label();
  14:          lblEdit.Text = "&nbsp;";
  15:          Table tbl = new Table();
  16:          tbl = (Table)e.Row.Parent;
  17:          GridViewRow myRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
  18:          DataTable dt = new DataTable();
  19:          dt = (DataTable)this.dtOCCRateList;
  20:  
  21:          for (int i = 0; i < count; i++)
  22:          {
  23:              TableCell myCell = new TableCell();
  24:              // need to create the edit hyperlink in the the footer 
  25:  
  26:              if (i == 0)
  27:              {
  28:                  // leave blank
  29:                  myCell.Controls.Add(new LiteralControl(""));
  30:              }
  31:              else
  32:              {
  33:                  // create the image and hyperlink 
  34:                  HyperLink editLink = new HyperLink();
  35:                  editLink.ID = "editLink" + random;
  36:                  
  37:                  // set the image url 
  38:                  editLink.ImageUrl = "~/library/images/ico-edit.gif";
  39:  
  40:                  // set the navigate url 
  41:                  editLink.NavigateUrl = "~/Default.aspx?Id=" + dt.Rows[0][i].ToString()
  42:                      + "&PId=" + AssetId.ToString();
  43:  
  44:                  // now add this hyperlink in the table cell
  45:                  myCell.Controls.Add(editLink);
  46:                  
  47:                  // add delete 
  48:                  HyperLink delLink = new HyperLink();
  49:                  delLink.ID = "delLink" + random;
  50:                  random++;
  51:  
  52:  
  53:                  delLink.ImageUrl = "~/Library/images/delete.gif";
  54:  
  55:                  // set the navigate url
  56:                  delLink.NavigateUrl = "~/Default.aspx?Id=" + dt.Rows[0][i].ToString()
  57:                      + "&PId=" + AssetId.ToString();
  58:  
  59:                  myCell.Controls.Add(new LiteralControl("&nbsp;"));
  60:                  myCell.Controls.Add(delLink);
  61:              }
  62:  
  63:              myRow.Cells.Add(myCell);
  64:              tbl.Rows.Add(myRow);
  65:          }
  66:      }
  67:  
  68:  }
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

A lot of times in the applications we require to pass comma separated values to the stored procedures, these values are contained in a custom object IList or IList<string> type. 

/// <summary>
/// Converts a list item property name value to comma seperated values
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Items"></param>
/// <param name="PropertyName"></param>
/// <returns></returns>
public static string ConvertTo<T>(IList<T> Items, string PropertyName) 
{
    StringBuilder builder = new StringBuilder();
    Type entityType = typeof(T);
 
    // iterate through the property
    foreach (T Item in Items)
    {
        if (string.IsNullOrEmpty(PropertyName))
            builder.Append(Item.ToString()).Append(",");
        else 
            // get the value of the property name passed
            builder.Append(
                entityType.GetProperty(PropertyName).GetValue(Item, null).ToString()
            ).Append(",");
    }
 
    return builder.ToString().TrimEnd(new char[] { ',' });
}
  • Currently 2 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

About Us

studio NETSOULS is a complete IT services company, offering strategy, design, development and implementation of the total solution for your web and IT initiatives. The solutions we provide, enables businesses to leverage leading edge technology to gain sustainable competitive advantages in today's marketplace.

We specialize in designing, developing and deploying the next generation of IT solutions including e-business solutions Read more...

Tags

This will be shown to users with no Flash or Javascript.

Contact Us

My status

Quote of the Day

Men are disturbed, not by the things that happen, but by their opinion of the things that happen

- Epictetus

NutritionVista

www.NutritionVista.com

Archives


Advertisements


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Log in