Popup windows in Javascript

In this tutorial we will learn how to create popup windows in javascript. Before creating popup windows let's understand what are popup windows.

Popup windows are additional windows infect additional web browser windows opened from a webpage. These windows are created by using javascript as a client side programming language.

Popup windows are widely used for the advertisement, to exchange the banners, polling, requesting signup for news letter etc.

Now let's look over the code to develop popup windows in javascript.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>popup windows in javascript</title>
<script language="javascript" type="text/javascript">
function openPopupWindow()
{
window.open("http://www.google.com",'Google','height=200, width=500,top=100,resizable=no,scrollbars=no,toolbar=no,status=no,menubar=no');

}
</script>
</head>
<body>
<form>
<input type="button" value="Click to open Popup Windows in Javascript" onclick="openPopupWindow();">
</form>
</body>
</html>

First of all we made a custom function and give it a name openPopupWindow(), in this function we simply call the built-in function windows.open() and give some parameters to window.open() function which are used for specifications for popup window that is going to be open. In this example the first parameter is webpage/website name, second parameter is the name given to the popup window, third parameter is the height, fourth is the width, fifth parameter handles the top margin to display popup window in the current window, sixth one is self explanatory, seventh parameter means there will be no scrollbar in the popup windows that is going to be open, eighth parameter means there will be no status bar, and last parameter means there will be no menubar in the popup window.

Happy Coding, Keep Coding…!
Read more...

How to fire OnIndexChanged event of Dropdownlist in asp.net

Sometimes people working with asp dropdownlists < asp:DropDownList runat="server"> feel very angry when OnIndexChanged() event of asp dropdownlist not fire. People go to debug and they feel more angry when they find that debugger is not going to OnIndexChanged() event of asp dropdownlist.

The reason why OnIndexChanged() event of dropdownlist not fire is the missing of
autopastback="true" attribute in the asp dropdown list, so here is the solution


<asp:DropDownList ID="ddl_SearchOption" runat="server" autopastback="true">


So this is the way to fire the OnIndexChanged event of Dropdownlist in asp.net Read more...

Compiler Error Message: CS0433: The type 'Microsoft.Reporting.WebForms.ReportDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\Microsoft.Report

One of my friend got this error while working on RDLC Reports in Visual Studio 2008, so here is the solution to this problem that did trick for us to solve this complicated looking error. You just need to go to web.config file and delete these four lines


<add assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>


Happy Coding, Keep Coding.....! Read more...

Sending emails with attachments in asp.net using C#

To send emails with attachment in asp.net using C# is quite easy. I have already written two tutorials that discuss sending emails in asp.net using C#. If you not read these tutorials then please read them first. If you want to send attachment with email in asp.net using C# then here’s the code that should be added in the sendEmail() function that I already discuss in my tutorials.

string FilePath;
FilePath = "c:\\yourfile.txt";
MailAttachment attach = new MailAttachment(strFilePath);
msg.Attachments.Add(attach);


So after adding these above mentioned lines of code, your sendEmail() function will be

public void sendEmail()

{
MailMessage msg = new MailMessage(txt_From.Text,txt_To.Text);

msg.CC.Add(txt_Cc.Text);

msg.Bcc.Add(txt_Bcc.Text);

msg.Subject = txt_Subject.Text;

msg.Body = Bodytext();

msg.Subject = txt_Subject.Text;

msg.IsBodyHtml = true;

string FilePath;

FilePath = "c:\\yourfile.txt";

MailAttachment attach = new MailAttachment(strFilePath);

msg.Attachments.Add(attach);

SmtpClient yourSmptpclient = new SmtpClient("localhost");

try{

yourSmptpclient.Send(msg);
}

catch(Exception Exp){

throw Exp;

}

}

So this is the simple way to send attachments with email in asp.net using C#.

Read more...

Getting controls of Gridview in C# code behind

In this tutorial we will learn how to get different controls of gridview in C# code behind. We normally get data from database and display it in gridview using different controls in gridview like label, textbox etc. In some cases we do need to get these controls of gridview in our C# code. Let’s have a look on how to get the gridviews' controls in C#.


Working_Gridview_Controls.aspx

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Width="100%" HorizontalAlign="Left" GridLines="None" EmptyDataRowStyle-ForeColor="Maroon" EmptyDataText="No Record(s) Found" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table border="0" style="width:100%; border:1px solid #e4e4e4" cellpadding="2" cellspacing="4">
<tr bgcolor="#e4e4e4" style="font-family:Verdana; font-size:10px;">
<td width="3%" align="center">
<asp:Label ID="lbl_Name" runat="server" Font-Bold="true"></asp:Label>
<asp:Label ID="lbl_City" runat="server" Font-Bold="true"></asp:Label>

<asp:Label ID="lbl_State" runat="server" Font-Bold="true"></asp:Label>

</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Working_Gridview_Controls.aspx.cs

public partial class special_instruction : System.Web.UI.Page
{
string myVar;


protected void Page_Load(object sender, EventArgs e)
{
//Your code will come here
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if(e.Row.RowType== DataControlRowType.DataRow)
{

myVar = ((Label)e.Row.FindControl("lbl_Name")).Text;

}

}

}

In Working_Gridview_Controls.aspx.cs I declared a global variable myVar and in rowdatabound event of gridview using this code ((Label)e.Row.FindControl("lbl_Srno")).Text; i get the Label Control of Gridview, in this example I am getting the Label having the id lbl_Name which lies inside the gridview.

So this is the way to get the gridviews' controls in C# and have fun :)
Read more...