Wednesday, December 7, 2011


In, Image class is usually used to write images. May it would have other drawbacks but I faced an issue which I am sharing:

My Image was CMYK format when I saved my image using Image class it converted it from CMYK to RGB which was not required.

I was using FileUpload control to get the bytes when I commented all the code which involved FileStream and MemoryStream and I just used FileUpload1.SaveAs (filePath);
It solved my problem.

Wednesday, June 8, 2011

How to hide/show an element using javascript in ASP.Net

// To Hide 
document.getElementById("lblCurrentSize").style.visibility = 'hidden'; 

// To Show
 document.getElementById("lblCurrentSize").style.visibility = 'visible';


Monday, May 23, 2011

How to enable/disable control using javascript in

 <script type="text/javascript">
    function Disable()
           // Disable server side button with following syntax
           document.getElementById("button1").disabled = true;
 </script >


Monday, May 16, 2011

how to forcefully postback from javascript in ASP.Net

I am taking a simple example and telling you the way how to achieve this.
    I want to postback my page when user presses "Enter" key while focus is in textbox. Write the following code in this way.
on page load write the following code:
txtbox1.Attributes.Add("onKeyPress", "KeyPressTextBox()");

User can check that value passed from cleint side in his page like this and he/she can ignore any other calls on this argument value

protected void Page_Load(object sender, EventArgs e)
if(HttpContext.Current.Request.Params["__EVENTARGUMENT"] == "argument")
            // Enter you code


 <script type="text/javascript">
  function KeyPressTextBox() {
  //var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (event.keyCode == 13) {
       event.returnValue = false;
       event.cancelBubble = true;
      __doPostBack('<%=UpdatePanel1.ClientID %>', "argument");

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
             <asp:TextBox ID="txtbox1" runat="server" Width="160px"></asp:TextBox>

Thursday, May 12, 2011

Removing double backslashes in C#

It adds the backslashes to indicate quotes in the middle of the string. The backslashes aren't actually there, the quotes are.
Remove the quotes like that:
myTestString.Replace("\"", string.Empty);

Friday, April 29, 2011

CrystalReportViewer is missing in VS.Net 2010 toolbox

After installing Crystal Report for Visual Studio.Net 2010

then add the reference of following dlls
CrystalDecisions.Windows.Forms.dll (Main)

and build the project then u will be able to see CrystalReportView control in toolbox.

Ping a url without opening in browser.

 private void BrowseUrl(string url)
                HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(url);

                // *** Return the Response data
                HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();

                Encoding enc = Encoding.GetEncoding(1252);  // Windows-1252 or iso-
                if (loWebResponse.ContentEncoding.Length > 0)
                    enc = Encoding.GetEncoding(loWebResponse.ContentEncoding);

                StreamReader loResponseStream =
                    new StreamReader(loWebResponse.GetResponseStream(), enc);

                string response = loResponseStream.ReadToEnd();

                if (response.Length != 0)
                   // You can write this response to some textbox here also

            catch (Exception ex)
                throw ex;

Friday, April 8, 2011

How to scroll to bottom in a textbox in C#

Use function called ScrollToCaret of textbox. You need to first set the caret position to the end of the text box, then call the ScrollToCaret function.
Here's how to do it:
        //move the caret to the end of the text
        textBox.SelectionStart = textBox.TextLength;
        //scroll to the caret

Saturday, March 26, 2011

Numeric textbox in ASP.Net

Although NumericUpDownExtender from Ajax toolkit can be used but it has drawbacks and UI issues as well. So I found the right solution under this URL:

It is really great control and fulfill almost all the needs. It is easy to use and understand.

Monday, March 21, 2011

Populating TimeZone list in ASP.Net

Following code will populate the controls in

//Populating in DropDownList (1)
this.DropDownList1.DataSource = TimeZoneInfo.GetSystemTimeZones();

//Populating in DropDownList (2)
foreach (TimeZoneInfo tmz in TimeZoneInfo.GetSystemTimeZones())
this.DropDownList1.Items.Add(new ListItem(tmz.DisplayName, tmz.Id));
//Populating in GridView
GridView1.DataSource = TimeZoneInfo.GetSystemTimeZones();

Friday, March 18, 2011

How to enter a new Line in ASP.Net

string text = "First Line" + <br/> + "Second Line";
// its result is
First Line
Second Line

Sunday, March 6, 2011

Crystal Reports Merge Modules for Visual Studio.Net 2008, 2010

There are no merger modules for Basic Crystal Report for Microsoft Visual 2008. Merge modules can be found until Vs.Net 2005. But now you have to install a redistributable
 .msi package located under “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5\CRRedist2008_x86.msi”.
Following are the helpful links:


For Visual Studio.Net 2010

Saturday, February 5, 2011

GWT widgets and SmartGWT widgets

When application is purely designed in GWT and it is decided at some stage that smartGWT widgets should be used for the functionality and beautification of the application then be careful.

I am sharing my personal experience in this case.
I do not find a sound reason for using SmartGWT in already built GWT application. I faced many difficulties in smartGWT. Only in one case SmartGWT is successful and that is, whole application should be in SmartGWT from scratch. SmartGWT and GWT widgets cannot live together.

Some of the problems are mentioned here: 

  1. SmartGWT's widgets' events do not fire properly for example: ListGrid's doubleClick and click events, Checkboxes' valuechanged events in Firefox 3.6 and amazingly these events work properly in IE6,7 and 8. So all browsers do not support in this case.
  2. SmartGWT widgets do not resize automatically, I had to handle this behaviour manually.
  3. You can not apply a new style on ListGrid easily becuase it has many inner styles. Every widgets of smartGwt has lots of CSS styles and they remain firing either you apply new styles or not.
  4. Z-Index is more obvious than any other issue. One has to set each SmartGwt's widget Z-Index attribute in CSS otherwise setting this attribute in code does not work.
  5. Although Showcase is amazing but there are no guarantees either each and every widget will fit in the page.
  6. SmartGWT widgets should not be used in a GWT's application. SmartGWT widgets fail in the containers of GWT.
  7. Width100() does not work, events do not fire etc etc
At last my Team Lead (Fahim Rauf) has decided to remove it fully. So he  designed new ListGrid using GWT's Flextable. We are all HAPPY now.

Tuesday, January 11, 2011

Tip # 9: Sorting ListGrid Data at runtime

listgrid.sort("columnName", SortDirection.ASCENDING);

Saturday, January 8, 2011

Tip# 8: Tooltip in ListGrid

Tooltip can be set at the level of ListGrid widget and at the level of row (ListGridRecord). Here are both mentioned:
1 - ListGrid Level
      listgrid.setTooltip("Here is your tooltip");
2 - ListGridRecord Level
       listgridfield.setShowHover(true); // it allows to tooltip at the level of grid row, by default it will show the text in the field but if you want to show the custom tooltip then use the following code 
listgridfield.setHoverCustomizer(new HoverCustomizer() {

     public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
return "Here is the custom value to show as a tooltip of the listgridfield (column)";