Home > front end >  I have an updated div, but my code-behind behave as it has never changed
I have an updated div, but my code-behind behave as it has never changed

Time:09-23

I have a div object (riddleIdHere), and js code that during the running inserts a number into this div. I want my C# code-behind to use this number, but the code-behind gives me an empty string like I have never inserted a number into this div. Can anyone help me, please?

Here's my div:

<div id='riddleIdHere' runat='server' style='display:none'></div>

Js:

document.getElementById("riddleIdHere").innerText = riddleid;

*riddleid is a numeric variable
my code-behind is supposed to update a data table using my InnerText:

sql = "UPDATE YHRiddles "  
    "SET rateSum  ='"  b   "' "  
    "WHERE id = '"   riddleIdHere.InnerText   "';";
Debug.WriteLine(riddleIdHere.InnerText);

The Debug.WriteLine is here to see why it doesn't work, and it prints an empty string.

CodePudding user response:

What you change on page using javascript its not automatically send on code behind.

To do that you have to create an other hidden input control (that is the actually one that can send post back insformations on code behind) and also write there what information's you need to send on value not anywhere else. The Value is the only one that you can send.

The InnerText on code behind is to give some information on how to render your control - did not have interactivity with the final page.

CodePudding user response:

You can create a Literal:

<asp:Literal runat="server" ID="riddleIdHere" Text="" Visible="false"></asp:Literal>

and then set asp literal text with js.

  • Related