0

I have a standard ASP web form like this:

<asp:Content ID="Content8" ContentPlaceHolderID="MainContent" runat="server">
<fieldset>
    <asp:Label ID="lblFirstName" runat="server" Text="First Name:"></asp:Label>
    <asp:TextBox ID="tctFirstName" runat="server"></asp:TextBox>
    <asp:Label ID="lblLastName" runat="server" Text="Last Name:"></asp:Label>
    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
    <asp:Label ID="lblEmail" runat="server" Text="E-Mail:"></asp:Label>
    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
    <asp:Label ID="lblPhone" runat="server" Text="Phone Number:"></asp:Label>
    <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</fieldset>
</asp:Content>

I saw a post does the work: How to post XML to server thru HTML form? Here is the code:

$("#myform").submit(function(){
  var formjson = $('#myform').serializeArray();
  var formxml = json2xml(formjson);
  $.post("/collect.php", { 'data': formxml }, function(data){ 
    // callback logic
  });
  return false;
});

The result I got is already empty for 'serializeArray()'. So my question is: 1. how this jQuery code works with 'ContentPlaceHolder' instead of 'form'? 2. Does this jQuery code work with standard ASP control fields, or it has to be HTML field? For example: I use as text input, but HTML is: Thanks in advance.

Community
  • 1
  • 1
howexg9
  • 93
  • 1
  • 6

4 Answers4

0

The placeholder is not actually an html tag First change this

<fieldset id='myfieldset'>
#bunch of tags
</fieldset>

in

$('#myform').serializeArray();

replace #myform with #myfieldset Also you could just replace #myform with #Content8 but doing it on the fieldset will produce less clutter.

Paul Swetz
  • 2,234
  • 1
  • 11
  • 28
0

Thanks Paul. Actually I did add a with id, then replace 'myform' with 'div id', but same thing. serializaArray() function returns nothing. I assume this function only recognize html attributes, not asp control attribute. Am I right? In order to use this function, do I need to replace all asp control elements to html elements first? If this is the case, how to replace asp:GridView? I do have something customization on this control. Any other thoughts?

howexg9
  • 93
  • 1
  • 6
0

I not sure you could use ASP.NET ContentPlaceHolder with JQuery SerializeArray.
According this example of SerializeArray, it should be a JQuery array of objects, like $(":input") meaning all the controls

You have to check underlying html client-side code, and see what ContentPlaceHolder is convert to. On my testing, with your code, I see that client-side is converted to

So you should use $(":input").serializeArray();

To recover data from your

Hope it helps,

0

I not sure you could use ASP.NET ContentPlaceHolder with JQuery SerializeArray.
According this example of SerializeArray, it should be a JQuery array of objects, like $(":input") meaning all the controls

You have to check underlying html client-side code, and see what ContentPlaceHolder is convert to. On my testing, with your code, I see that client-side

<asp:TextBox ID="tctFirstName" runat="server">

is converted to

<input name="ctl00$MainContent$tctFirstName" type="text" id="MainContent_tctFirstName" />

So you should use

$(":input").serializeArray();

To recover data from your <asp:TextBox>
I had check on my system, and its returns correct data on SerializeArray()

Hope it helps,