Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2012, 10:10 AM
Authorized User
 
Join Date: Feb 2007
Posts: 39
Thanks: 2
Thanked 2 Times in 2 Posts
Default Popup at the end of a button event

Hello all,
in my aspx page I have a button that save several values in the database.
I need to insert a popuup at the end of the operation.
At the moment the code is:

protected void btnSendRequest_Click(object sender, EventArgs e)
{
var myDbAccess = new DBAccess();
Event newEvent = (Event)Session["NewEvent"];

myDbAccess.SaveEvent(newEvent);

// Insert here a PopUp like "Successfully saved!"

}

How can I accomplish this?
Luigi
 
Old February 14th, 2012, 01:57 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

Hi Luigi
at first: PierLuigi Collina!
There are several ways to do this:

1- show result using a label:
Code:
protected void btnSendRequest_Click(object sender, EventArgs e)
{
var myDbAccess = new DBAccess();
Event newEvent = (Event)Session["NewEvent"];

myDbAccess.SaveEvent(newEvent);


// Show Result
ResultLabel.Text = "Successfully Done!";


}
Note to set EnableViewState property of ResultLabel to false

<asp:Label ID="ResultLabel" runat="server" EnableViewState="false"></Label>

this setting means that 'State' (in a simple word: property values) is not saved in ViewState so Text or Other property value is not available in PostBack. so the displayed message disappears.


================
2- Alert using JavaScript

there are several ways to implement this solution.

2-1:
place a label named 'AlertLabel' at the bottom of your aspx page, and use this command:
Code:
protected void btnSendRequest_Click(object sender, EventArgs e)
{
var myDbAccess = new DBAccess();
Event newEvent = (Event)Session["NewEvent"];

myDbAccess.SaveEvent(newEvent);


// Alert Result
AlertLabel.Text = @"<script type='text/javascript'>
          alert(' Successfully Done! ');
</script>";
}
2-2:
declare a protected or public property named 'ShowSuccess' and use it in aspx page:
Code:
protected bool ShowSuccess;

protected void btnSendRequest_Click(object sender, EventArgs e)
{
var myDbAccess = new DBAccess();
Event newEvent = (Event)Session["NewEvent"];

myDbAccess.SaveEvent(newEvent);


// Show the Success result
ShowSuccess = true;
}
and in your aspx page use:
HTML Code:
<% if(ShowSuccess){ %>
    <div class='Success'>
        Successfully Done!
    </div>
<% } %>
__________________
happy every time, happy every where

Reza Baiat

Last edited by irProject; February 14th, 2012 at 02:02 PM..
 
Old February 14th, 2012, 02:11 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

for better view you can use jQuery methods:

http://www.jQuery.com

http://www.jQueryUI.com

I advice you (!!!) to learn javascript and javascript framworks like jQuery, YUI, etc. because it's really powerful. I've read in microsoft's documents that next generation of Office Word is based on JavaScript and HTML5!
in the next version of JavaScript (2.0) you can define classes, datatypes, inherit classes, make packages, etc. in a simple word (browser based C# or dynamic C#)
__________________
happy every time, happy every where

Reza Baiat
 
Old February 14th, 2012, 03:16 PM
Authorized User
 
Join Date: Feb 2007
Posts: 39
Thanks: 2
Thanked 2 Times in 2 Posts
Default

So is worth to learn jQuery?
What's the difference between jQuery and jQueryUI?

Luigi

Last edited by Ciupaz; February 14th, 2012 at 03:45 PM..
 
Old February 14th, 2012, 03:59 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default Yes

Hi Luigi
jQuery says: write less, do more

for example if you want to load a page (Test.aspx) in a div (with id="page1") you can write:

$("#page1").load("Test.aspx");

it loads test.aspx in page1 div! even you can partially load it:
$("#page1").load("Test.aspx #div1");
the above statement loads div1's value into page1

Google has wrote it's auto-complete with jQuery!

jQuery is one of javascript libraries that I think it's the most powerful js Library. others are: YUI (Yahoo Utility Interface) widely used by yahoo (fully used in Yahoo! Mail), Dojo, MooTools, Prototype, etc
YUI is supported by Yahoo!
jQuery is supported by every one that uses it!

see domes and take a tour
http://jqueryui.com/demos/

in asp.net you can use Microsoft's js library (Microsoft Ajax Library) with useful tools, but jQuery is very light and easy to load.

javascript libraries has grew after AJAX release. I'll write more about jQuery (getting started!) in next posts.

Cheers!
__________________
happy every time, happy every where

Reza Baiat
 
Old February 14th, 2012, 04:08 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default no difference

Hi Luigi

jQueryUI provides UserInterface tools for jQuery library.

jQuery can be extended. you can write plugin for jQuery :

HTML Code:
<script type="text/javascript">
jQuery.fn.SomeExtension = function(){
  // do something here
}

// now you can use:
jQuery("#div1").SomeExtension();
</script>
__________________
happy every time, happy every where

Reza Baiat
 
Old February 14th, 2012, 04:24 PM
Authorized User
 
Join Date: Feb 2007
Posts: 39
Thanks: 2
Thanked 2 Times in 2 Posts
Default

Very interesting, I think I'll buy a book about jQuery.

Luigi





Similar Threads
Thread Thread Starter Forum Replies Last Post
Popup Button Selection sarashinai BOOK: Beginning Mac OS X Programming 0 April 23rd, 2008 08:53 AM
Adding Multiple Event to button in layered PopUp saqlain.abbas ASP.NET 1.0 and 1.1 Professional 1 June 28th, 2007 04:05 AM
How to open a popup when back button is pressed Vadivel Javascript How-To 1 May 12th, 2006 03:08 AM
Popup without X button? chrscote Javascript How-To 1 June 2nd, 2005 01:27 PM
About Button event and Keydown event zhangxujun1981 XSLT 1 March 6th, 2004 04:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.