Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
i am trying to use jquery sample in aspx web form
bit about sample code
this samole code shows a center screen popup window with fadein and fadeout effect
now whats my problem
i tried for 2 days on implementing jquery in aspx web form but failed on every try.
same jquery runs like butter in html
i am using vs 2008
installed hotfix for intelsense successfully
put jquery-1.6.2.js in same folder
put jquery-1.6.2vsdocs.js for intellsense in same folder
when i put same html code in aspx web form in the form tag after runing in browser and clicking on button popup doesnt show himself at all but when i put
<input type="submit" value="Press me please!" />
out side the form tag it runs perfectly which is useless
where i am going wrong
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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">
<head runat="server">
    
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>yensdesign.com - How to create a stuning and smooth popup in jQuery</title>
	<link rel="stylesheet" href="general.css" type="text/css" media="screen" />
	
	<script src="jquery-1.2.6-vsdoc.js" type="text/javascript"></script>
	<script src="popup.js" type="text/javascript"></script>
</head>
<body>
    
    <form id="form1" runat="server">
 		<a href="http://www.yensdesign.com"><img src="logo.jpg" alt="Go to yensdesign.com"/></a>
		<div id="button"><input type="submit" value="Press me please!" /></div>
		<div id="popupContact">
		<a id="popupContactClose">x</a>
		<h1>Title of our cool popup, yay!</h1>
		<p id="contactArea">
			Here we have a simple but interesting sample of our new stuning and smooth popup. As you can see jQuery and CSS does it easy...
			<br/><br/>
			We can use it for popup-forms and more... just experiment!
			<br/><br/>
			Press ESCAPE, Click on X (right-top) or Click Out from the popup to close the popup!
			<br/><br/>
			<a href="http://www.yensdesign.com"><img src="logo.jpg" alt="Go to yensdesign.com"/></a>
		</p>
	</div>
	<div id="backgroundPopup"></div>
    <div>
    
    </div>
    </form>
</body>
</html>


JavaScript
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
Posted
Updated 19-May-12 5:47am
v2
Comments
Ed Nutting 19-May-12 9:10am    
Hi there, could you post your JavaScript code as well please? Otherwise it's gonna be hard to work out what's with it...

Thanks,
Ed
mehdilahori 19-May-12 11:45am    
hi Ed thanks for replying
i have not gone to any institute to learn asp.net and i have no teacher
i learned all these things from great brains out there like you you can see my work at betasite.somee.com
here is my popup.js code
[Edit: Code placed into question]

Hi there,

Having tested it the answer is obvious! There isn't a problem with your JavaScript nor even in most of your HTML. The problem lies the the fact that you are using a submit button. In your non-ASPX page you do not have a form, so there is nothing to submit when the submit button is clicked and so, the browser doesn't try to submit anything. So there isn't a page refresh. However, when you put your HTML into a form, there is now a form to submit. So when you press your button the browser immediately submits the form. This causes essentially a page refresh and so the pop-up never seems to have appeared.

So the solution is to change the button type from a Submit button, to just a button. So replace the following line:
HTML
<div id="button"><input type="submit" value="Press me please!" /></div>


with this:

HTML
<div id="button"><input type="button" value="Press me please!" /></div>


You can see in the typeattribute I have changed it from a Submit to a Button - this will stop it from submitting the form and will just run your click event.

Hope this helps,
Ed
 
Share this answer
 
Comments
mehdilahori 20-May-12 0:09am    
thanks Ed. it was a great learning experience the way you explained it was like my mother is trying to correct me where i am going wrong.
with the help of you Ed i learned new lesson on TYPE attribute which belongs to html.now i have another question
when i replaced html input button with asp button, that didn't work let me explain a bit more when i replaced this line
<input type="button" value="Press me please!" />
with this one
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton
unfortunately that didn't work
i was again back at same place where i was standing before your solution.
now here is my question
why an asp button or link button is not working with this script
Ed Nutting 20-May-12 4:44am    
Thank you, i'm glad I could help. Onto your new issue. Well when you use an ASP link button or just button, it has to convert them into actual html because they don't exist in the W3C Standard. So, if you were to use developer tools in your browser to view the html, you would see that the html for an ASP button is in fact an input of type submit not button, and thus you are back to the original problem that I explained before. So, either you have to use an html input of type button or you need to redesign your code to show the message when the page loads after they have clicked the button.

I hope this solves your new problem,
Ed
mehdilahori 20-May-12 7:48am    
thanks Ed for explaining
i got your points
actually what i am trying to do that i have a datalist having someinitial information about an item an and a details view asp link button right now when user clicks on details link button, detailed information of a particular item is shown on another page and obviously with query string
but now i want to show detail information on a popup window in the same page when i put the sane popup code in datalist i achieved my results 10% that means only very first item of the datalist is showing the popup window after clicking the detail button and rest of the items are not showing popup window, is it because i am using html type button instead of asp button, this is a tricky situation, if i use asp button i would not be able to use popup effect and if i use html type button i would not be able to show popup window in all the items in datalist i googled this issue and some developers asked same thing but did not got any solution
any suggestions my dear teacher Ed
thanks once again and have crispy day
Ed Nutting 20-May-12 8:04am    
Hmmm...hard to say what the issue is here. In any case it is not due to your use of the html button. You should debug your JavaScript in browser using Developer Tools to see if the click events for the extra view details buttons work. Is there a demo page that I can look at where your having this problem with the popup?

Thanks,
Ed
mehdilahori 20-May-12 9:48am    
i am trying upload the page but i am having some problem i think server doesn't support ajax or jquery
here is my datalist code
<asp:DataList ID="dl1" runat="server"
HorizontalAlign="Right" RepeatColumns="1"
onitemcommand="Repeater1_ItemCommand1" Width="638px" align="left">
<itemtemplate>

<div>
<table style="font-weight: bold;">
<tr>
<td>
<asp:Image ID="Image1" width="100%" height="100%" runat="server"
ImageUrl='<%# Eval("filename", "{0}") %>' />
</td>
<td style="width: 200px;">
PROPERTY TYPE
<asp:Label ID="lblCategory" runat="server"
Text='<%# Eval("[category]") %>'>

<br></br>
PROPERTY ID:
<asp:Label ID="lblHouse_id" runat="server" Text='<%# Eval("[house_id]") %>'>

<br/>
Phase:
<asp:Label ID="lblPhase" runat="server" Text='<%# Eval("[phase]") %>'>

<br>
</br>
<br></br>
address:
<asp:Label ID="lbladdress" runat="server" Text='<%# Eval("[address]") %>'>

<br />
<asp:LinkButton ID="btnDetails" runat="server"
CommandArgument='<%# Eval("[house_id]") %>' CommandName="details"
Text="View Details" />
<br />
<br>
</br>
<div id="button"><input type="button" value="Press me please!" /></div>
<div id="popupContact">
x
<p id="contactArea">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("[house_id]") %>'>

</p>
</div>
<div id="backgroundPopup"></div>


i am laughing at my self
thanks
Without seeing the JQuery you are actually using it is difficult to be certain. However, a common problem is not taking into account the name mangling that occurs with ASP.NET.

For example, if you code was

$("#some_element_id")


This would find the element

HTML
<input id="some_element_id" />


but when the attribute runat="server" is used ASP.NET will prefix the id of the rendered element depending on the container it is in. So it will be something like this

<input id="ctrl_001_some_element_id" />


Now the JQuery selector won't find the element because the id is different. A way around this is to use

$("id[$='some_element_id']")


which will select any element who id ends with some_element_id, regardless of the prefix.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900