4 Replies - 13304 Views - Last Post: 28 March 2012 - 11:50 AM Rate Topic: -----

#1 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

I want to display a message box using asp.net controls and C#

Posted 23 March 2012 - 12:19 AM

I am trying to write code using asp.net in some files that show a message box when the orange button is clicked. I have displayed them in my code, but I only want to display them when the button is clicked (in this case, it's the "Register" button). However, right now, it also displays when I open the NewCustomerRegistration.aspx page I have created in Visual Studio 2010, before clicking the "Register" button.

Here is my main web form, Insurance.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Insurance.aspx.cs" Inherits="Insurance" %>

<!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">     

<!--Insurance.htm-->

<head>
<script type="text/javascript">
    function show_alert()               // show_alert function is called when the "Get A Quote" button is clicked
    {
        alert("Work in Progress");      // this code will pop the "Work in Progress" message on the screen
    }

    function open_contacts()            // open the popup for the "Contact.htm" content 
    {
        // window.showModalDialog will make this window pop up without minimize or maximize buttons in the title bar
        // _blank ensures that this window will open in a new browser/tab
        window.showModalDialog("Contacts.htm", "_blank", "width=850, height=850");
    }

    function open_privacy() {
        // _blank ensures that this window will open in a new browser/tab
        window.open("Privacy.htm", "_blank", "toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=500");
    }

    function open_termsAndConditions() {
        // the "Terms and Conditions" pdf will open 
        window.open("Terms and Conditions.pdf", "_blank");
    }

    function open_register_info() {
        new_window = open("", "hoverwindow", "width=500,height=400,left=10,top=10");


        new_window.document.open();

        /* These statements will set the backround color and print information about why people
        should register for fSIG and specifies the symbol for which fields are mandatory in 
        the registration form */
        new_window.document.write('<html><title></title>');
        new_window.document.write('<body bgcolor=\"#00FF40\">');
        new_window.document.write('<h1>Why Register? <br/></h1> ');
        new_window.document.write('Registration is creating a profile which is necessary to guard privacy of our valuable customers.<br/><br/>');
        new_window.document.write('The information you give is on your profile is essential to use our services correctly.<br/><br/>');
        new_window.document.write('In the registration form fields marked with * are mandatory.<br/><br/>');
        new_window.document.write('<center>Thank you!</center>');
        new_window.document.write('</body></html>');

    }
</script>
    <title>
    
    </title>
</head>

<body>
<center> 
<img src="images/fSIG banner.bmp" alt="home" />                         <!--places the fSIG banner.bmp file on top of the web page-->
</center>

<center> 


<a href='NewCustomerRegistration.aspx'>New Customer Registration</a>                               <!--creates inactive link "New Customer Registration"-->
<a href='#' onmouseover="open_register_info()">Why Register?</a>        <!--opens the "Why Register?" popup window when the mouse cursor is moved 
                                                                            over this link-->
<a href='ExistingCustomerLogin.aspx'>Existing Customer Login</a>                                 <!--creates inactive link "Existing Customer Login"-->
<br />
<b>
<font color="orange">                                                   <!--sets font color-->
<br />Let Us Help You Get Quotes on Affordable Home Insurance from fSIG<br />
</font>
</b>
</center>

<center>
<p style="text-align:justify">                                          <!--justifies the text on the web page-->
<font face="arial" color="blue">                                        <!--chooses the font and text color-->
When looking for affordable home insurance it is important to request quotes from
many insurance providers.  Those who shop around for their home insurance tend to
find the best deals available for their home insurance market.  Home insurance costs
depend largely on the location of the home, how susceptible it will be to natural
disasters, like hurricanes and earthquakes, as well as other factors.  Homeowners
can typically save by increasing their deductible to a manageable rate.  Others find
affordable home insurance by taking advantage of loyalty programs offered by
insurance companies -- they buy both their home and car insurance from the same 
provider.  Many affordable home insurance companies compete with rates, so the 
best avenue would be to obtain quotes from many different sources
</font>
</p>
</center>
 
<form id="form1" runat="server">
<div>
<center>        <!--creates a button with the following options, and calls the show_alert function when "Get A Quote" button is clicked-->                                                                
<asp:Button BackColor="Maroon" Width="170" ID="quote" Text="Get A Quote" Font-Size="Large" Font-Bold="true" ForeColor="Orange" runat="server" ></asp:Button>
</center>
</div>
</form>

<center>        
<br />
<table border="1">      <!--choose table border styles-->

<tr>        <!--create a table for the buttons "Contacts", "Privacy Policy", and "Terms and Conditions", while choosing their 
                width and height in pixels, background color, and text color.  Clicking "Contacts" button calls the open_contacts() 
                function.  Clicking "Privacy Policy" button calls the open_contacts() function. Clicking "Privacy Policy" button calls 
                the open_termsAndConditions() function.-->  
<td><button style="width:180px; background-color:#5EFB6E; color: #A52A2A" onclick="open_contacts()">Contacts</button></td>      
<td><button style="width:180px; background-color:#5EFB6E; color: #A52A2A" onclick="open_privacy()">Privacy Policy</button></td>
<td><button style="width:180px; background-color:#5EFB6E; color: #A52A2A" onclick="open_termsAndConditions()">Terms And Conditions</button></td>
</tr>
</table>                <!--end table-->
</center>

</body>                 <!--body closing tag-->
</html>                 <!--html closing tag-->



And when the "New Customer Registration" link is clicked, the NewCustomerRegistration.aspx page is shown. See code below

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewCustomerRegistration.aspx.cs" Inherits="NewCustomerRegistration" %>
<%@ Import namespace="System.Text" %>

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

<script runat="server">

   

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>

    <center> 
    <!--I created this bitmap file in Paint, then saved it as "fSIG banner", then added it to my webpage by adding
    a description (e.g.: alt="home")-->
    <img src="images/fSIG banner.bmp" alt="home" />      
    </center>

    <asp:Label Text="Getting Started-->Home Insurance-->Registration" ForeColor="Orange" Font-Names="Arial" Font-Size="Large"  Font-Bold="true" runat="server" ></asp:Label><br/><br />
   
    <asp:Label Text="We follow the highest industry standards to safeguard the confidentiality of your personal information and 
    secure the transmission of your information from your computer.  Please fill out this form as completely as
    possible to ensure an accurate quote."  ForeColor="Blue" font-italic="true" runat="server" ></asp:Label><br/><br/>

    <form id="form1" runat="server">
    <div>
    
    <asp:Label Text="First Name *     " Width="120" ForeColor="Maroon" runat="server" ></asp:Label>     
    <asp:TextBox ID="FirstName" BorderColor="Maroon" Width="200" runat="server"></asp:TextBox><br/><br/>
    
    <asp:Label Text="Last Name *      " Width="120" ForeColor="Maroon" runat="server" ></asp:Label>      
    <asp:TextBox ID="LastName" BorderColor="Maroon" Width="200" runat="server"></asp:TextBox><br/><br/>
    
    <asp:Label Text="Email *          " Width="120" ForeColor="Maroon" runat="server" ></asp:Label>           
    <asp:TextBox ID="Email"  BorderColor="Maroon" Width="280" runat="server"></asp:TextBox><br/><br/>
    
    <asp:Label Text="Zip Code *       " Width="120" ForeColor="Maroon" runat="server" ></asp:Label> 
    <asp:TextBox ID="ZipCode"  BorderColor="Maroon" Width="80" runat="server"></asp:TextBox><br/><br/>       

    <asp:Label Text="Valid Password * " Width="120" ForeColor="Maroon" runat="server" ></asp:Label> 
    <asp:TextBox ID="Password" BorderColor="Maroon" Width="120" runat="server"></asp:TextBox>
    <asp:LinkButton ID="rules" Text="See Password Rules" Font-Size="X-Small" Target="_blank" runat="server"></asp:LinkButton><br/><br/><br/>                     




    <asp:Label Text="* Required Field" ForeColor="Red" Font-Names="Arial" Font-Size="Small"  Font-Bold="true" runat="server" ></asp:Label><br/><br/><br/> 
    

    <center>
    <asp:Button BackColor="Orange" Width="200" ID="register" Text="Register" ForeColor="Blue" onclick="Page_Load" runat="server"></asp:Button>
    </center>

    </div>
    </form>

    

</body>
</html>




And finally, this is the code for my NewCustomerRegistration.aspx.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NewCustomerRegistration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       Response.Write("<script language='javascript'>alert('New Customer Registered');</script>"); 
    }
}



I've seen another way to show dialog messages, such as MessageBox.Show. Would I have to create a function called _doPostBack in my NewCustomerRegistration.aspx.cs file?

This post has been edited by gutchman84: 23 March 2012 - 12:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: I want to display a message box using asp.net controls and C#

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,278
  • Joined: 12-June 08

Re: I want to display a message box using asp.net controls and C#

Posted 23 March 2012 - 07:00 AM

Have you tried the modal popup extender in the ajax library?

https://ajaxcontrolt...t.codeplex.com/


Also moving to ASP.NET
Was This Post Helpful? 0
  • +
  • -

#3 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

Re: I want to display a message box using asp.net controls and C#

Posted 23 March 2012 - 11:27 AM

View Postmodi123_1, on 23 March 2012 - 07:00 AM, said:

Have you tried the modal popup extender in the ajax library?

https://ajaxcontrolt...t.codeplex.com/


Also moving to ASP.NET


You mean I have to download an add-on for Visual Studio 2010 to get the help I need?

My instructor suggests that I use ClientScript.RegisterStartupScript to achieve this. Do you know anything about this method? I'm having little success finding the help I need, not even on this website: http://www.w3schools.com
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,278
  • Joined: 12-June 08

Re: I want to display a message box using asp.net controls and C#

Posted 23 March 2012 - 11:37 AM

It's an addon from MS that I use often with all my projects. Since a 'popup' box doesn't exist on a webpage world you can either use some sort of lightbox effect (third party), or chuck another dll in the ASPX page. I find the modal popup works pretty slick and my clients haven't had a problem seeing it.


FYI - why not read up on the method in the MSDN help docs?

http://msdn.microsof...iptmanager.aspx
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,278
  • Joined: 12-June 08

Re: I want to display a message box using asp.net controls and C#

Posted 28 March 2012 - 11:50 AM

http://webdesign.tut...-reveal-plugin/

There's something that is more jquery based.. you can plunk that into your aspx form and give it a shot.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1