Results 1 to 5 of 5

Thread: [RESOLVED] Help with Javascript prompt in ASP.net VB page

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    27

    Resolved [RESOLVED] Help with Javascript prompt in ASP.net VB page

    I'm inexperienced enough with Javascript that I couldn't tell if any of the other posts addressed my issue or not. Sorry if this is a repeat and feel free to point me to the post, if there is one.

    I have an ASP.net VB page with a checkbox for reject and a textbox for Quantity Rejected. I'm trying to get a javascript prompt, asking for the reject qty, to open when the checkbox is checked. The user will enter a quantity in the prompt and the quantity rejected will fill with that quantity. Once the text in the quantity rejected textbox changes that will trigger some other stuff from the codebehind. If it makes a difference my checkboxes and textboxes are asp controls rather than html input controls.

    I originally had the script working, sort of, from the script on the markup page with the script below. I say sort of because it was firing whether the checkbox was checked or unchecked.
    Code:
        var qrcheck = document.getElementById('bolRej1');
        if (qrcheck.checked) {
            function rQty() {
                var rq = prompt('Enter Reject Qty', '');
                document.getElementById('txtQtyRej').value = rq;
            }
        }
    I've now moved the script to the checkbox's OnCheckedChanged event in the codebehind.

    Code:
        Protected Sub bolRej1_CheckedChanged(sender As Object, e As EventArgs) Handles bolRej1.CheckedChanged
    
            If bolRej1.Checked = True Then
    
                Dim sb As New System.Text.StringBuilder()
                sb.Append("<script Type ='javascript'>")
                sb.Append("function rQty() {")
                sb.Append("var rq = prompt('Enter Reject Qty', '');")
                sb.Append("document.getElementById('txtQtyRej').value = rq;")
                sb.Append("}</script>")
    
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "rQtyFunction", sb.ToString(), True)
    
            End If
        End Sub
    With the codebehind method the prompt never opens. I can include a break point and see that it is running through the stringbuilder and apparently running the script but the prompt isn't opening and I just see //]]> at the bottom of my page and see the code below in view source.

    Code:
    <script type="text/javascript">
    //<![CDATA[
    <script Type ='javascript'>function rQty() {var rq = prompt('Enter Reject Qty', '');document.getElementById('txtQtyRej').value = rq;}}</script>//]]>
    </script>
    I'm not sure what I'm missing. Am I completely off track. Any and all help would be greatly appreciated!
    Last edited by knelson312; Nov 4th, 2014 at 06:54 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width