Monday, October 22, 2007

How Data Grid rendered in FireFox


It is very surprising that how Data Grid is rendered in FireFox. Black lines for rows and columns are drawn which is not the case with IE. It is like a table which is having border color set to black. If any style or themes is applied then also it is of no use. If you try to see the source of the page you will not find anything which is causing this problem.

I have also encountered the same problem when my QA engineer reported me that some black lines are appearing when I try to open page X in FireFox. I tried to find am I doing anything wrong with the CSS file or with my Skin file but that was not the problem.

After some googling, I found the solution but not the cause. The solution is set style property of Data Grid to “border-collapse: separate”. When I applied the same style to my page, no black color lines were appearing on the page with FireFox.

I am still wondering about the cause and how this particular style solves my problem.
Well, this world is full of strange things.

Happy Programming…
Enjoy…

Thursday, October 18, 2007

To refresh Parent Window from Pop Up Window


Sometimes it is required to refresh your Parent Window through Child Window, Here is a small piece of java script code which will solve your problem.

window.opener.location.reload();

Put this code in any function of Child Window. When that function is called parent window will be reloaded.

How to send Mail From Sql


This is a very common situation when it is required to send mails. There are so many ways to send mail.

The very common is Sql mail. Through Sql server 2005 you can send mail.

There are two methods available
1.DataBase Mail
2. Thorugh OLE

Here is the Stored Procedure to send mail through OLE.

Just copy this prodedure and run it in your database...

--WSA_sp_SendEmail 'virendra@mailserver.local','virendra@mailserver.local','Hi','Test Mail From CDO'
CREATE PROCEDURE [dbo].[WSA_sp_SendEmail]
@From varchar(100),
@To varchar(1000),
@Subject varchar(250),
@Body varchar(max),
@CC varchar(1000) = null
AS
BEGIN
Declare @iMsg int
Declare @hr int
Declare @source varchar(255)
Declare @description varchar(500)
Declare @output varchar(1000)
EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT
Print @From
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', '10.0.0.100'
EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null
--Print @To
EXEC @hr = sp_OASetProperty @iMsg, 'To', @To
EXEC @hr = sp_OASetProperty @iMsg, 'From', @From
if (@Cc <> '')
EXEC @hr = sp_OASetProperty @iMsg, 'Cc', @Cc
EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject
EXEC @hr = sp_OASetProperty @iMsg, 'HtmlBody', @Body
EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL
IF @hr <>0
select @hr
--print @hr
BEGIN
EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUT
Print @hr
IF @hr = 0
BEGIN
SELECT @output = ' Source: ' + @source
PRINT 'hi'
PRINT @output
SELECT @output = ' Description: ' + @description
PRINT @output
END
ELSE
BEGIN
PRINT ' sp_OAGetErrorInfo failed.'
RETURN
END
END
EXEC @hr = sp_OADestroy @iMsg
END

*Please change the SMTP server address in the Procedure. Currently it is set to 10.0.0.100, Change this address according to your SMTP server Address.

To send the mail one have to "Enable OLE Automation".

Go to Sql server source configuration area and enable OLE Automation from the options list.

Sql server Source Configuration area is under Start->Microsoft Sql Server-> Configuaration Tools..

Enjoy Mailing


Sunday, October 14, 2007

Difference between theme and stylesheetTheme attribute.

The Page directive includes the attribute Theme and StylesheetTheme.You can use both to apply themes to a page. So, the question is: If you have a Theme attribute and a StylesheetTheme attribute for the Page directive, what is the difference between the two?

<%@ Page Language=”VB” StylesheetTheme=”Theme1” %>

The StylesheetTheme attribute works the same as the Theme attribute in that it can be used to apply a theme to a page. The difference is that the when attributes are set locally on the page within a particular control, the attributes are overridden by the theme if you use the Theme attribute. They are kept in place, however, if you apply the page’s theme using the StylesheetTheme attribute. Suppose you have a text box control like the following:

<asp:Textbox ID=”TextBox1” Runat=”server”
ForeColor=”#ffffff” />

In this example, the ForeColor settings is overridden by the theme if you have
applied it using the Theme attribute in the Page directive. If, instead, you applied the theme using the StylesheetTheme attribute in the Page directive, the ForeColor settings remain in
place, even if they are explicitly defined in the theme.

Thursday, October 11, 2007

ref and out in C#

When we pass a parameter as ref to a method, the method refers to the same variable and changes made will affect the actual variable.

Even the variable passed as out parameter is similar to ref, but there are few implementation differences when you use it in C# .

Argument passed as ref must be initialized before it is passed to the method, where as in case of out its is not necessary,but after a call to the method as an out parameter the variable must be initialized.

When to use ref and out parameter. out parameter can be used when we want to return more than one value from a method.

Enjoy..



Change Url of Popup without closing it

On one of my project, I encountered a problem.I have 2 buttons on the page and on click of any button i have to open a pop up window.
Let's say on click of button 1 -> pop up window should open with Page1.aspx
and on click of button 2 -> pop up window should open with Page2.aspx.

But the problem was I have to use only one instance of pop up window.One way is I can close the existing pop up window and open another will other Url.But this is not I want.

I want to use the same window and if it is open just change the Url.

After some googling I Found a solution:-

var childRef = null;

function openpopup(page)
{
if (childRef == null childRef.closed)
{
childRef = window.open(page1 , '');
}
else
{
childRef.location.href=page;
childRef.focus();
}
return false;
}

This Java Script function was called onClientClick event of the button and respective page value was passed as parameter.

ChildWindowObject.Location.href = Some Url does the trick for me.It will change the Url of popup.

One thing to notice here..

If I dont use childRef.focus(); this code then what is going to happen If the pop up window is open (not Minimized) and when childRef.location.href=page; this gets excuted pop up window will be minimized automatically.

To keep it not minimized I used childRef.focus();. This will set the focus again on the window.

Enjoy..

Happy Programming...

Parse and TryParse

Parse method is used to parse any value to specified data type.
For example

string test = "42";
int32 Result;
Result = Int32.Parse(test);

This will work fine bt what if when you are aware about the value of string variable test.

if test="abc"....

In that case if u try to use above method, .NET will throw an exception as you are trying to convert string data to integer.

TryParse is a good method if the string you are converting to an interger is not always numeric.

if(!Int32.TryParse(test,out iResult))
{
//do something
}


he TryParse method returns a boolean to denote whether the conversion has been successfull or not, and returns the converted value through an out parameter.

**declare variable iResult of Int32.

Enjoy

Wednesday, October 03, 2007

ASP.NET 2.0 Features: app_offline.htm

There is a simple way to bring down your ASP.NET 2.0 application. The only thing you have to do is to create simple html file called App_offline.htm and deploy it to your ASP.NET 2.0 web application root directory. The rest is handled by ASP.NET runtime internal routines.

The way app_offline.htm works is that you put the file in the root directory of the application. When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the App_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online.
back to top