Results 1 to 5 of 5

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

  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.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    27

    Re: Help with Javascript prompt in ASP.net VB page

    Anybody???

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Help with Javascript prompt in ASP.net VB page

    When doing a Prompt in JavaScript you still need to use an Alert to actually show your message.

    Something like this -

    function rQty() {
    var rq = prompt('Enter Reject Qty', '');
    alert(rq+'!');
    document.getElementById('txtQtyRej').value = rq;
    }
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Help with Javascript prompt in ASP.net VB page

    the code you're building in the string builder should be just the js code... you shouildn't be adding the script tags, that appears to be generated by the RegisterStartupScript ... also, registering it only injects it into the page... it still needs to run somehow. I'd keep it where it was in the page on the onClick event. If it's firing off even when it's unchecked, then you should be looking at why ...

    why are you defining a function inside the if? just have the code... no need to define a function there, especially since that puts you in the same boat as the register script method, it never gets called.

    Following what I'm reading here - http://stackoverflow.com/questions/9...ked-javascript

    it should be like this:
    Code:
        var qrcheck = document.getElementById('bolRej1');
        if (qrcheck.checked) {
                var rq = prompt('Enter Reject Qty', '');
                document.getElementById('txtQtyRej').value = rq;
        }
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    27

    Re: Help with Javascript prompt in ASP.net VB page

    So here's one remaining question...

    I have two controls that will need to call that function. The first is the checkbox control noted above. I also have an MPN dropdownlist that has an item "Wrong Part R'cvd". If that item is selected I also need to check the bolRej1 and get the reject quantity. I'm already using the "SelectedIndexChanged" event to check the checkbox but since that just triggers the checkedChanged event and not the onclick event, I need to find a way to call the function from the checkedchange event or by the dropdownlist event. Any thoughts?

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