Monday, December 24, 2012

Send E-Mail using C# Asp .Net

==>>First you need have  to design the aspx page like :---

  <div>
<table  align="center">
<tr>
<td colspan="2" align="center">
<b>Send Mail using C# Asp.Net</b>
</td>
</tr>
<tr>
<td>
Gmail ID:
</td>
<td>
<asp:TextBox ID="txtUserEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Gmail Password:
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Subject:
</td>
<td>
<asp:TextBox ID="txtSubjectText" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
To:
</td>
<td>
<asp:TextBox ID="txtToEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td valign="top">
Body:
</td>
<td>
<asp:TextBox ID="txtBodyPart" runat="server" TextMode="MultiLine"  ></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSend" Text="Send" runat="server" onclick="btnSend_Click" />
</td>
</tr>
</table>
</div>

 

==>>Secound you need have  to write  the the code on  aspx.cs page  on BtnSend Click event  :---

   protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage Msg = new MailMessage();
            Msg.From = new MailAddress(txtUserEmail .Text);
            Msg.To.Add(txtToEmail.Text);
            Msg.Subject = txtSubjectText.Text;
            Msg.Body = txtBodyPart.Text;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.Credentials = new System.Net.NetworkCredential(txtUserEmail .Text, txtPassword .Text);
            smtp.EnableSsl = true;
            smtp.Send(Msg);
            Msg = null;
            Page.RegisterStartupScript("Message", "<script>alert('E-Mail Successfully Send...');if(alert){ window.location='Default.aspx';}</script>");
        }
        catch (Exception ex)
        {
         
        }
    }

Note:-You need to add this namespace in .cs file>>  using System.Net.Mail;

Hope this will help you  

 

Wednesday, November 21, 2012

Query String With Example

==>>First you need have one page that have one textbox ID="NameTxtbox" and Have one button ID=" btnSubmit" Then on the button click you need write this code:---


 
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Redirect("MainPage.aspx?Name="+NameTxtbox.Text);
}


==>> If you Want to have multiple control value on the Mainpage.aspx then you need to write this code:--


protected void btnSubmit _Click(object sender, EventArgs e)
{
Response.Redirect("MainPage.aspx?Name="+NameTxtbox.Text+"&Fname="+FNameTxtbox.Text);
}

 ==>> Get the value of Query String on the Another page:---


protected void Page_Load(object sender, EventArgs e)
{
Lblname.Text = Request.QueryString["Name"];
LblfName.Text = Request.QueryString["Fname"];
}

Thursday, March 29, 2012

Select All Check Box In Asp .Net With Java Script

Add This Code In Header Section Of your Aspx Page
1.


   1:  <script type="text/javascript">   
   2:     function SelectAllAndDeSelectAllCheckBox(Chk)
   3:  { 
 
   5:        var oItem = Chk.children; 
   6:      var theBox= (spanChk.type=="checkbox") ? Chk: Chk.children.item[0]; 
   7:       xState=theBox.checked;  
   8:       elm=theBox.form.elements; 
    9:       for(i=0;i 
  10:    
  11:           if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)  
  13:           {   
  16:             if(elm[i].checked!=xState)    
  19:           }
  20:  script>



After The Add this code in Header Section You Need take A Grid View and Write This Code ..


   1:   
   2:  <asp:templatefield headertext="Select">
   3:    <headertemplate>  
   4:    <input blogger_onclick="javascript:SelectAllAndDeSelectAllCheckBox(this);"  
         id="chkAll" runat="server" type="checkbox">  
   5:   headertemplate> 
   6:    <itemtemplate>
   7:   <asp:checkbox blogger_oncheckedchanged="CheckBox1_CheckedChanged"  
         id="CheckBox1" runat="server" autopostback="true">
   8:    asp:checkbox>itemtemplate>
   9:   asp:templatefield>




Hope This Help You