?
Solved

The form doesn't show up by using Jquery.

Posted on 2012-03-28
11
Medium Priority
?
341 Views
Last Modified: 2012-03-28
I am testing a pop up form by clicking an asp.net button. However it is not working.
Thanks for help.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebTest._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Button ID="Button1" runat="server" Text="Button" Class="someButton" />
    <div id="divPopUp" style="display:none;"> 
         <p>test</p>
     </div> <script type="text/javascript">

    $(document).ready(function () {

        $("someButton").click(function () {
        alert('hi')
            $("#divPopUp").dialog({ width: 600, height: 500 });
        });

    });
 
    </script>
</asp:Content>

Open in new window

0
Comment
Question by:zhshqzyc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 25

Expert Comment

by:Rouchie
ID: 37776823
Can you provide the rendered code to make it easier for us to debug?

Also, move the JQuery code to the <head> content area, after the references to the JS files.
0
 

Author Comment

by:zhshqzyc
ID: 37776859
Did you mean?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>
	Home Page
</title><link href="Styles/Site.css" rel="stylesheet" type="text/css" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

</head>
<body>
    <form method="post" action="Default.aspx" id="ctl01">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTYwODIwNTg5MWRkQwiVen3YNjdrvbC8uDMr4NwFCsYKTDAz1FBJ38DLehk=" />
</div>

<div class="aspNetHidden">

	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLh9MX2DALT8MqYCEqLBIC7BJJfRxqIFlKYcSwj0UtLo3soMoLztB1JVMb0" />
</div>
    <div class="page">
        <div class="header">
            <div class="title">
                <h1>
                    My ASP.NET Application
                </h1>
            </div>
            <div class="loginDisplay">
            </div>
            <div class="clear hideSkiplink">
            </div>
        </div>
        <div class="main">
            
    <input type="submit" name="ctl00$MainContent$Button1" value="Button" id="MainContent_Button1" Class="someButton" />
    <div id="divPopUp" style="display:none;"> 
         <p>test</p>
     </div> <script type="text/javascript">

    $(document).ready(function () {

        $("someButton").click(function () {
        alert('hi')
            $("#divPopUp").dialog({ width: 600, height: 500 });
        });

    });
 
    </script>

        </div>
        <div class="clear">
        </div>
    </div>
    <div class="footer">
        
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37777041
$(document).ready(function () {

        $("#Button1").click(function () {
        alert('hi')
            $("#divPopUp").dialog({ width: 600, height: 500 });
        });

    });

Open in new window

0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:zhshqzyc
ID: 37777058
But it is not working as well, did I reference the correct css and jquery library?
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37777086
use firebug to debug the script and see if alert works or not
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 37777095
somebutton is a class name, so it should be reference in JQuery as $(".someButton")

Alert should have a semi colon after it --->  alert('hi');

Then, you need to prevent the click function actually submitting.  Just checking the doc's to find out about this
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 2000 total points
ID: 37777108
Full working code:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  <script type="text/javascript">

    $(document).ready(function () {

        $(".someButton").click(function (event) {
		
	    event.preventDefault();
            $("#divPopUp").dialog({ width: 600, height: 500 });
        });

    });
 
    </script>
</head>

Open in new window

0
 

Author Comment

by:zhshqzyc
ID: 37777191
It looks making progress.
I created a table. After I clicked the button, the form did pop out then vanished. How can it be stuck there?
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebTest._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Button ID="Button1" runat="server" Text="Button" Class="someButton" />
    <div id="divPopUp" style="display:none"> 
         <table><tr><td>col1</td><td>col2</td></tr>
         <tr><td>ty</td><td>jkl</td></tr>
         </table>
     </div> <script type="text/javascript">

                $(document).ready(function () {
                    $(".someButton").click(function () {
                       
                        $("#divPopUp").dialog({ width: 600, height: 500 });
                    });
                });
 
    </script>
</asp:Content>

Open in new window

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 37777236
You have not included my new JQuery.  Please refer to my working code - move the working code into the <head> section.  This prevents the button submitting the page after it has been clicked.
0
 

Author Closing Comment

by:zhshqzyc
ID: 37777252
Great.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37777260
$(document).ready(function () {
                    $(".someButton").click(function () {
                       
                       var $dialog = $("#divPopUp").width(600).height(500).dialog({autoOpen=false;title='Dialog'});
                       $dialog.dialog('open');
                    });
                });
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question