1

I have googled this quite a lot and must still be missing something. The method creates the pop-up dialog fine but the text box does not get populated when I press the button.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Proj1.Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ButtonSubmit() {
            var isPressed = document.getElementById('SubmitPressed');
            isPressed.Value = "True";
            alert('You have submitted your request. ');           
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="SubmitPressed" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ButtonSubmit();"/>
        </div>
    </form>
</body>
</html>
Salbrox
  • 143
  • 1
  • 15
  • Does this answer your question? [getElementById not finding control generated by ASP.net](https://stackoverflow.com/questions/4595823/getelementbyid-not-finding-control-generated-by-asp-net) – vahdet Dec 13 '19 at 10:51
  • What is this? `isPressed.Value` supposed to do? How is that supposed to work? – VDWWD Dec 13 '19 at 10:55
  • @VDWWD I want to send the text value to the text box which I will hide and pull the value into code behind – Salbrox Dec 13 '19 at 12:13
  • Yes, but what makes you think using `Value` will assign the value to the TextBox? Javascript is case sensitive! – VDWWD Dec 13 '19 at 12:22
  • @VDWWD I used document.getElementById('SubmitPressed').value = "True"; and it worked, thank you. – Salbrox Dec 13 '19 at 12:25

2 Answers2

0
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ButtonSubmit() {
            var isPressed = document.getElementById('SubmitPressed');
            isPressed.value = "True";
            alert('You have submitted your request. ');
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="SubmitPressed" ClientIDMode="Predictable" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ButtonSubmit();"/>
    </div>
    </form>
</body>
</html>

Try above code in place of your existing textbox

Dan-J
  • 19
  • 5
0

I needed to change .Value to .value since Javascript is case sensitive as per @VDWWD's comment.

var isPressed = document.getElementById('SubmitPressed');
isPressed.value = "True";
Salbrox
  • 143
  • 1
  • 15