Popup window in Web Application with asp.net c sharp

Hello Friends Today you will get a new thing which will really helpful in your life and
in programming world.
In this article  i am telling you too many things which are essential in every application
and you have need to learn these.
Step: 1 First of all as you know make a new web site With VB or C# and Prepare out
design as given below in picture

Step 2: Now Make Out a function which will use to page class and composed a
popup window with code behind method.
In which you can pass your custom message and Make good you web application too much.
———————————————————————————–
Public Sub DisplayMessage(ByVal objPage As System.Web.UI.Page, ByVal message As String)
‘Replace end of line characters with JavaScript \n newline character.
message = Replace(message, vbCrLf, “\n”)
message = Replace(message, vbCr, “\n”)
message = Replace(message, vbLf, “\n”)
message = Replace(message, “”””, “\”””)
‘Replace ugly database tags with (slightly) more meaningful text.
message = Replace(message, “[DataDirect ADO Sybase Provider]”, “Sybase Error:”)
message = Replace(message, “Native Warning code”, “Error #:”)
Dim pageType As Type = objPage.GetType()
Dim displayName As String = “displayMessage”
Dim cs As System.Web.UI.ClientScriptManager = objPage.ClientScript
If (Not cs.IsStartupScriptRegistered(pageType, displayName)) Then
Dim displayText As String = “alert(“”” & message & “””);”
cs.RegisterStartupScript(pageType, displayName, displayText, True)
End If
End Sub
————————————————————————-
Step 3: Now Friend go on page design and Double click on Submit Button and then make a new
Method which should be bool type and Make Validation on Your Page (server side)
———————————————————————————–
Private Function IsValid() As Boolean
If (TextBox1.Text = “” Or TextBox1.Text = String.Empty) Then
DisplayMessage(Page, “Please enter your name!!!”)
Return False
ElseIf (TextBox2.Text = “” Or TextBox2.Text = String.Empty) Then
DisplayMessage(Page, “Please enter your class!!!”)
Return False
ElseIf (TextBox3.Text = “” Or TextBox3.Text = String.Empty) Then
DisplayMessage(Page, “Please enter your date of birth!!!”)
Return False
ElseIf (TextBox4.Text = “” Or TextBox4.Text = String.Empty) Then
DisplayMessage(Page, “Please enter your profession!!!”)
Return False
Else
Return True
End If
End Function
————————————————————————-
Step 4: On click procedure of Submit Button Write down these lines
———————————————————————————–
If IsValid().Equals(True) Then
strName = TextBox1.Text.ToUpper()
strClass = TextBox2.Text.ToUpper()
strDob = TextBox3.Text.ToUpper()
strProfession = TextBox4.Text.ToUpper()
Response.Write(strName + “<br/>” + strClass + “<br/>” + strDob + “<br/>” + strProfession)
End If
————————————————————————-
Step 5: If you Want to Handle Exception then Make a New  Class File With this you will learn how
can we use Class file and Use of Oops.
how can make master settings in web config file for mail sending and recievning in our project or application
For this In Go into web config file and Make Appsettings and write down these master lines for application
AppSeting Section is For Unique Key Value definition in your applicaiton
If your are unable to identify this section in web config file then can take help of Image Which is
Given below
———————————————————————————–

<appSettings>

<!–this is your mail server ip address from mail will go and receive–>

<add key=”Mail_Server” value=”193.193.193.10″/>

<!–this is your company mail user name–>

<add key=”Mail_UserName” value=”demeanormc@owmnahar.com”/>

<!–this is your company mail address from mail go and receive–>

<add key=”Mail_MailFrom” value=”demeanormc@owmnahar.com”/>

<!–this is your company mail address password–>

<add key=”Mail_Password” value=”123#”/>

</appSettings>

———————————————————————————–

Step 6: Now Make a Function of boolean type in your class File Which will mail to you automaticaly whenever

Exception Happen in your project.With this help you can decrease head ache of project handling or you will have to no

need to hand over any system handler can observe and take care your application with this Wather your application

running good or not.

———————————————————————————–

Imports Microsoft.VisualBasic

‘this namespace is essential to read out web config file appsetting section reading

Imports System.Configuration.ConfigurationManager

Namespace OrientDeveloper

Public Class Class1

Public Function ProjectExceptionMail(ByVal strMessage As String, ByVal strPageName As String) As Boolean

‘Message Body

Dim ExceptionDate As String

ExceptionDate = Date.Now.ToString()

Dim MailMessage As New StringBuilder

MailMessage.Append(“<table align=’left’ cellpadding=’0′ style=’width: 100%’>”)

MailMessage.Append(“<tr>”)

MailMessage.Append(“<td colspan=’3′ style=’width: 100%; text-align: left’>”)

MailMessage.Append(“<h1 style=’color: #CC3300′>”)

MailMessage.Append(“Project Problem Notification</h1>”)

MailMessage.Append(“</td>”)

MailMessage.Append(“</tr>”)

MailMessage.Append(“<tr>”)

MailMessage.Append(“<td style=’width: 5%’>”)

MailMessage.Append(“&nbsp;”)

MailMessage.Append(“</td>”)

MailMessage.Append(“<td style=’width: 90%’>”)

MailMessage.Append(“<table cellpadding=’0′ style=’width: 100%; float: left;’>”)

MailMessage.Append(“<tr>”)

MailMessage.Append(“<td style=’width: 100%; text-align: left’>”)

MailMessage.Append(“</td>”)

MailMessage.Append(“</tr>”)

MailMessage.Append(“<tr>”)

MailMessage.Append(“<td style=’padding-left: 30px; text-align: justify; width: 100%’>”)

MailMessage.Append(“Error notification :-your project has a exception,which is given below:”)

MailMessage.Append(“<br/><span style=’text-decoration: underline;font-weight:bold;color: #0099cc’>” + strMessage + “</span>.<br/> Please do rectify to this exception as soon as possible.”)

MailMessage.Append(“<br/> Exception Date Is :<span style=’text-decoration: underline;font-weight:bold;color;#456599′>” + ExceptionDate + “</span>.”)

MailMessage.Append(“<br/> Page Name Is :<span style=’text-decoration: underline;font-weight:bold;color;#456599′>” + strPageName + “</span>.”)

MailMessage.Append(“</td>”)

MailMessage.Append(“</tr>”)

MailMessage.Append(“<tr>”)

MailMessage.Append(“<td style=’padding-left: 30px; width: 100%’>”)

MailMessage.Append(“&nbsp;”)

MailMessage.Append(“</td>”)

MailMessage.Append(“</tr>”)

MailMessage.Append(“</table>”)

‘End of Message Body

Dim MailFrom As String

Dim MailTo As String

Dim MailSubject As String

MailFrom = “demeanormc@owmnahar.com”

MailTo = “OrientDeveloper@gmail.com”

MailSubject = “Project Problem”

Dim smtp As New Net.Mail.SmtpClient(AppSettings(“Mail_Server”).ToString())

Dim NetworkCredentials As New System.Net.NetworkCredential

NetworkCredentials.UserName = AppSettings(“Mail_UserName”).ToString()

NetworkCredentials.Password = AppSettings(“Mail_Password”).ToString()

smtp.Credentials = NetworkCredentials

Dim MailData As New System.Net.Mail.MailMessage(MailFrom, MailTo, MailSubject, MailMessage.ToString())

MailData.IsBodyHtml = True

Try

smtp.Send(MailData)

Return True

Catch ex As Exception

Return False

Finally

MailData.Dispose()

End Try

End Function

End Class

End Namespace

———————————————————————————–

Step 7: Now Friends you go into code file of your page and make four line method for page exception handling and

Acces to this mail sending method.

Before this you go into source file of your presentation layer of page and make a div as given below

——————————————————————————————————————

<%@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”Default.aspx.vb” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head runat=”server”>

<title></title>

<style type=”text/css”>

.style1

{

width: 100%;

border: 2px solid #800000;

background-color: #eeeeee;

}

</style>

</head>

<body>

<form id=”form1″ runat=”server”>

<%–this is exception handler div–%>

<div id=”DivException” runat=”server” style=”background-color: Black; color: White;

border-color: #0099CC; font-size: medium; font-family: Helvetica; font-style: normal;

font-weight: bold;”>

</div>

<%–end of exception handler div–%>

<div>

<table cellpadding=”0″ cellspacing=”0″ class=”style1″>

<tr>

<td>

Enter Your Name

</td>

<td>

<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>

</td>

<td>

&nbsp;

</td>

</tr>

<tr>

<td>

Enter Your Class

</td>

<td>

<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>

</td>

<td>

&nbsp;

</td>

</tr>

<tr>

<td>

Enter Your DOB

</td>

<td>

<asp:TextBox ID=”TextBox3″ runat=”server”></asp:TextBox>

</td>

<td>

&nbsp;

</td>

</tr>

<tr>

<td>

Enter Your Profession

</td>

<td>

<asp:TextBox ID=”TextBox4″ runat=”server”></asp:TextBox>

</td>

<td>

&nbsp;

</td>

</tr>

<tr>

<td>

&nbsp;

</td>

<td>

<asp:Button ID=”Button1″ runat=”server” Text=”Submit” />

</td>

<td>

&nbsp;

</td>

</tr>

</table>

</div>

</form>

</body>

</html>

——————————————————————————————————————

Step 8: Now go into page code file and Import to class namespace and make object of your class as given below

——————————————————————————————————-

Imports OrientDeveloper

Partial Class _Default

Inherits System.Web.UI.Page

Dim objClsMail As New Class1

Dim strPageName As String

Dim strName, strClass, strDob, strProfession As String

————————————————————————————–

And  Now make this method

————————————————————————————–

Private Sub CurrentPageException(ByVal ex As String)

DivException.Attributes.Add(“display”, “block”)

DivException.InnerText = ex.Replace(ex, “Due to server problem there is error on this action,please try after some time…”)

strPageName = Request.FilePath()

objClsMail.ProjectExceptionMail(ex.ToLower(), strPageName)

End Sub

———————————————————

Step 9: Into page load write down these lines of code

———————————————————

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If (Not (IsPostBack)) Then

DivException.Attributes.Add(“display”, “none”)

DivException.InnerText = String.Empty

End If

End Sub

———————————————————

Now On submit button click code will be as given below

——————————————————–

Try

If IsValid().Equals(True) Then

strName = TextBox1.Text.ToUpper()

strClass = TextBox2.Text.ToUpper()

strDob = TextBox3.Text.ToUpper()

strProfession = TextBox4.Text.ToUpper()

Response.Write(strName + “<br/>” + strClass + “<br/>” + strDob + “<br/>” + strProfession)

End If

Catch ex As Exception

CurrentPageException(ex.Message)

Finally

Call Refresh()

End Try

——————————————————–

Refresh method is will be as below

——————————————————-

Private Sub Refresh()

TextBox1.Text = String.Empty

TextBox2.Text = String.Empty

TextBox3.Text = String.Empty

TextBox4.Text = String.Empty

End Sub

Now Run to Your Application and Be Happy ,enjoy in this world!!!

Image Gallery For Some part of Code Clearification
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

One thought on “Popup window in Web Application with asp.net c sharp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s