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);
}
4
  • Is it literally all content on aspx? Or is there masterpage, or more stuff on the aspx? Commented Dec 21, 2016 at 14:34
  • stackoverflow.com/questions/5088450/… - maybe this might help? Commented Dec 21, 2016 at 14:36
  • Please do not refer to JavaScript as JScript. That has a different but related meaning that is just going to lead to confusion. Commented Dec 21, 2016 at 14:43
  • you are confusing client side and server side. They dont mix but can comunicate through ajax, rest api,post/get request Commented Dec 21, 2016 at 14:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.