Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Good Afternoon,

I want to pass data from my html page to Aspx page and this HTML page is rendered into Aspx page at run time by using <!--#INCLUDE FILE="..\HTML\GroupRegistration.html"--> in aspx source.

In JavaScript file my method is
C#
$(document).ready(function ()
{

    $("#btnSave").click(function () {

        var GroupName = document.getElementById('txtGrpName').value;
        var GroupType = document.getElementById('ddlGrpType').selectedIndex;
        var GroupAddress = document.getElementById('txtAddress').value;
        var FirstName = document.getElementById('txtFirstName').value;

try {
$.ajax({
type: "POST",
url: "GroupRegistration.aspx",
data: {
"param1=": +GroupName, "param2=": +GroupType, "param3=": +GroupAddress, "param4=": +FirstName, },
C#
contentType: "application/x-www-form-urlencoded; charset=utf-8",
               dataType: "html",
               success: function (msg) {
               },
               error: function (xhr, status, error) {
                   alert('Error');
               }
           });
       }
       catch (e) {
           alert(e);
       }

   });
});

and I am getting the values in aspx.cs file like below.
string txtGrpName = Request.Form["param1"];
int ddlGrpType = Convert.ToInt32(Request.Form["param2"]);
string txtAddress = Request.Form["param3"];
string txtFirstName = Request.Form["param4"];




and then in javascript file I am getting exception "$ is undefined"


So please give solution to my problem?

And explain the procedure to pass data.

Thanks in advance
Posted
Updated 12-Dec-13 22:53pm
v2

If you need to add $.ajax ,You have to add jQuery into your page is as below.

XML
<head>
<script type="text/javascript" src="../scripts/jquery 1.10.2.js">
</script>
</head>
 
Share this answer
 
Comments
Member 8557048 13-Dec-13 6:15am    
Even after adding the above it is not working
Sampath Lokuge 13-Dec-13 7:00am    
Have you added the jQery to your project ?
Member 8557048 13-Dec-13 7:11am    
Yes I added all those files
Sampath Lokuge 13-Dec-13 7:14am    
OK then debug with the 'chrome dev tool' and let me know the exact error and from where is it coming exactly ?
Just put this line on top of document.ready function:-
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>

Hope, this will helps you....
 
Share this answer
 
Comments
Member 8557048 13-Dec-13 6:14am    
I added that also in html file but it is not working
Jain Nishant 13-Dec-13 6:57am    
What's the error u r getting??? Try to debug also and see....
Member 8557048 13-Dec-13 7:07am    
Same as $ is undefined
Jain Nishant 13-Dec-13 7:15am    
Have you put your jquery code into script block... like:-
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" language="javascript">

/// put your jquery code here...
</script>

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