Google Brother Up

2009/02/27

Data does not show when updated windw is reopened

Suppose I am opening a new window with window.open() and saving some changes in the window and closing the window. When I reopen the window it shows the previous values. (It display data which had appeared before the changes) after refreshing only I am getting recent data. I need new data only while opening the window.


To solve this we do: -


Response.Cache.SetCacheability(HttpCacheability.NoCache) will have to be put on onload()


Javascript code to refresh the page called window.refresh() will not work here.

212 unique visitors

2009/02/24

Code to embed a flash file in a .NET application

{object width="250" height="400"
  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
  codebase="http://fpdownload.macromedia.com/pub/
  shockwave/cabs/flash/swflash.cab#version=8,0,0,0"}
{param name="movie" value="mp3player.swf" /}
{embed src="mp3player.swf" width="250" height="400"
  type="application/x-shockwave-flash" pluginspage=
  "http://www.macromedia.com/go/getflashplayer" /}
{/object}

205 unique visitors

Alert Message using Response.Write in Web through C# Code

1) Hardcoded Alert

Response.Write("{script}alert("Hello");{/script}");

2) Variable Alert

string txtName = "Hello " + txtText.Text;
Response.Write("{script}alert('" + txtName + "');{/script}");

205 unique visitors

2009/02/23

Required Field Validator does not fire in Firefox - Solution

Always write code under Page.IsValid scope if Required Field Validator does not fire in Firefox but fires in IE.

try
 {
       if (Page.IsValid)
     {
            // code
      }
 }
 catch (Exception ex)
{
       string msg = ex.Message;
}

203 unique visitors

2009/02/17

SET NOCOUNT ON; - Improve performance of stored procedure

Benefit: - By Setting NOCOUNT as ON we improve the performance of the stored procedure

Problem: -
One of the biggest things that DBAs try to do on a daily basis is to ensure that their database systems run as fast as possible.  As more and more users access the databases and the databases continue to grow, performance slow downs are almost inevitable. Based on this, DBAs and developers should do everything they possibly can to keep performance related issues in mind early in the database lifecycle.  This is not always easy to do, because of the unknowns and the changes that occur over time, but there are some simple things that can be done and we will touch upon one of these in this tip.

Solution: -
Sometimes even the simplest things can make a difference.  One of these simple items that should be part of every stored procedure is SET NOCOUNT ON.  This one line of code, put at the top of a stored procedure turns off the messages that SQL Server sends back to the client after each T-SQL statement is executed.  This is performed for all SELECT, INSERT, UPDATE, and DELETE statements. Having this information is handy when you run a T-SQL statement in a query window, but when stored procedures are run there is no need for this information to be passed back to the client.

By removing this extra overhead from the network it can greatly improve overall performance for your database and application.

If you still need to get the number of rows affected by the T-SQL statement that is executing you can still use the @@ROWCOUNT option.  By issuing a SET NOCOUNT ON this function (@@ROWCOUNT) still works and can still be used in your stored procedures to identify how many rows were affected by the statement.

Microsoft even realized the issue that this creates and has changed the stored procedure templates from SQL Server 2000 to SQL Server 2005.

Here is the old template style available in SQL Server 2000 without the SET NOCOUNT ON.


192 unique visitors

2009/02/13

A potentially dangerous Request.Form value was detected from the client... (Solution - Solved)

When you come across an error saying "A potentially dangerous Request.Form value was detected from the client..." you can be very sure that you need to do 2 things to solve it.

1) Set the aspx page set ValidateRequest="false" so that the page directive looks like this: - {%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddPressRelease.aspx.cs"
Inherits="AddPressRelease" ValidateRequest="false" %}

2) While submitting the page inside the submit method html encode all textboxes like below: -

objPressReleaseBO.Title = Server.HtmlEncode(txtTitle.Value);
objPressReleaseBO.Description = Server.HtmlEncode(txtDescription.Value);

Your problem will be solved. :)

186 unique visitors

2009/02/04

Readonly Textbox - Error Solve - sans Javascript

How to Solve: -
1) Error in getting the value of a read only textbox in asp.net.
2) Create a readonly textbox without using Javascript.

1) When u add a text box as: -

{asp:TextBox ID="txtDate" runat="server" ValidationGroup="Submit" ReadOnly="true" Text="" TabIndex="2" /}

2) and try to get the value of the textbox in code behind as: -

objPressReleaseBO.Date = Convert.ToDateTime(txtDate.Text);

then

Error Occurs: String was not recognized as a valid DateTime.

as

the value Text of the text box cannot be read by the asp.net control

Solution:

1) take an html textbox {input runat="server" type="text" name="txtDate" id="txtDate" value="txtDate" tabindex="2" readonly /}

2) capture the value of the textbox from code behind as


objPressReleaseBO.Date = Convert.ToDateTime(txtDate.Value);

Solved: - 

1) Then the text box becomes read only
2) Also the value of the textbox is possible to capture from code behind.

179 unique visitors

2009/02/03

Difference between a Label and a Literal in ASP.NET

1. Label is heavy weight so increases size of page while literal is light weight, so decreases size of page.
2. Label supports cssclass property but literal does not support cssclass property.
3. Label cannot be used to insert html code directly but literal can be used to insert html code directly so dynamically html tags can be created.
4. When AssociatedControl property is set, Label produces an html label as its output but when AssociatedProperty is omittedm then Label text will be wrapped in a span.

For more help refer: http://forums.asp.net/t/710459.aspx

177 unique visitors

Ad Rotator Simplest Example

1. Add two images called Microsoft.jpg, Google.jpg in images folder.

2. Create an XML page advt.xml by replacing { with <>

{?xml version="1.0" encoding="utf-8" ?}
{Advertisements}

  {Ad}
    {ImageUrl}~/images/Google.jpg{/ImageUrl}
    {NavigateUrl}http://www.google.com{/NavigateUrl}
    {AlternateText}Google{/AlternateText}
    {Impressions}1{/Impressions}
    {Keyword}Google{/Keyword}
  {/Ad}

  {Ad}
    {ImageUrl}~/images/Microsoft.jpg{/ImageUrl}
    {NavigateUrl}http://www.microsoft.com{/NavigateUrl}
    {AlternateText}Microsoft{/AlternateText}
    {Impressions}2{/Impressions}
    {Keyword}Microsoft{/Keyword}
  {/Ad}

{/Advertisements}

3. Create a Page called AdRotatorPage.aspx

{%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdRotatorPage.aspx.cs" Inherits="AdRotatorPage" %}

{!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"}

{html xmlns="http://www.w3.org/1999/xhtml" }
{head runat="server"}
    {title}Ad Rotator Example{/title}
{/head}
{body}
    {form id="form1" runat="server"}
    {div}
        {asp:AdRotator ID="adrDAL" runat="server" Target="_self" AdvertisementFile="~/advt.xml"
        Height="350px" Width="500px" /}
    {/div}{br /}
    {div}
        {asp:AdRotator ID="adrDAL2" runat="server" Target="_self" AdvertisementFile="~/advt.xml"
        Height="350px" Width="500px" OnAdCreated="adrDAL2_AdCreated" /}
    {/div}
    {/form}
{/body}
{/html}

4. Create a Page called AdRotatorPage.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class AdRotatorPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void adrDAL2_AdCreated(object sender, AdCreatedEventArgs e)
    {
        e.NavigateUrl = "http://vaichatt.blogspot.com";
        //e.ImageUrl = "~/images/Yahoo.jpg"; // if this image is present there in images folder
    }
}


177 unique visitors

Drop Down List

1. http://www.janetsystems.co.uk/Articles/NetArticles/tabid/74/itemid/161/modid/449/Default.aspx