How can I retrieve the value from a window.prompt()
alert box in my C# Code Behind file? I know it's a simple line of JavaScript, but I want to execute it and get the result within my Code Behind. Whether it's done through a <script>
tag in the .aspx
file or directly in the .aspx.cs
file doesn't matter to me.
I've considered calling the script (from the C# portion) and then storing the return value in a hidden field, but I'm wondering if there's a more efficient way to achieve this.
One possible approach is as follows:
.aspx file:
<script>
function getValue() {
document.getElementById('HiddenField').value = window.prompt('Please enter your answer:', '');
}
</script>
.aspx.cs file:
////////////////////////////////////////////////
//The HiddenField.Text now contains the desired value//
//////////////////////////////////////////////
Do you have any suggestions for improving this process?