1

I have two separate pages. One with a HTML page involving JavaScript (bunch of functions etc.) and an .aspx page.

I have some array in html page and I want to send them(using JavaScript) to .aspx to store them into a database.

I have tried hidden field, creating a form etc. All I get is null. How can I pass my arrays to aspx to store them in database later? I can't use jQuery.

function openPopup() {
        window.open("Default.aspx",  "scrollbars=yes, width=900,height=500,left=430,top=100");
        return false;
    }
function control() {
        var a = JSON.stringify(x);// x and y are my arrays
        var b = JSON.stringify(y);

        var btnId = '<%= HiddenField1.ClientID%>';
        var btnId2 = '<%= HiddenField2.ClientID%>';
        document.getElementById(btnId).value = a;
        document.getElementById(btnId2).value = b;                       
    }

IN HTML

<button onclick="openPopup()">POP</button> //opens the aspx page

IN ASPX

<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Database" />
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <asp:HiddenField ID="HiddenField2" runat="server" />
</form>

IN ASPX.CS

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Write(HiddenField1);
}
danwellman
  • 9,068
  • 8
  • 60
  • 88
ZackyV
  • 13
  • 3
  • Is it literally all content on aspx? Or is there masterpage, or more stuff on the aspx? – Andrei Dec 21 '16 at 14:34
  • http://stackoverflow.com/questions/5088450/how-to-retreive-form-values-from-httppost-dictionary-or - maybe this might help? – NoobishPro Dec 21 '16 at 14:36
  • Please do not refer to JavaScript as [JScript](https://en.wikipedia.org/wiki/JScript). That has a different but related meaning that is just going to lead to confusion. – mason Dec 21 '16 at 14:43
  • you are confusing client side and server side. They dont mix but can comunicate through ajax, rest api,post/get request – giammin Dec 21 '16 at 14:53

1 Answers1

1

You will need to send the data to the server using AJAX (preferably) or using a traditional form submission (page will be reloaded after submission).

The server cannot access the HTML elements once the page has been rendered in the browser.

danwellman
  • 9,068
  • 8
  • 60
  • 88