Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

javascript/vb.net - Issue with Web Handler(.ashx)

Having issue with the code. The goal is that when a value is read into a field, take that via .JS/.AShx to the db and back.  If the value is a red_shoe, then red.wav file plays...if the value is a green_shoe then green.wav file plays...

it runs fine up thru the vb.net and javascript but errors out when it tries to call the .ashx page...
//// javascript code....



function whichShoe() {
 
    shoe_number = ReceivedDate = document.getElementById(var_txtShoe_id).innerHTML;

    // PASS THE VALUE OF THE SHOE INTO THE .ASHX TO RUN AGAINST THE WEB PAGE TO SEE WHAT VALUE SHOULD RETURN...
    var xmld = load_xml("../Handler/shoe.ashx?Task=GetWhichShoe=" + shoe_number)

    if (xmld != null) {
        // Validation Completed
        // var procRetVal = getNodeValue(xmld, "retVal")

        if (xmld = 2) {
            red_shoe()
        }
        else {
            green_shoe()
        }

    }
    else {
        alert(" Please Contact The System Administration For Support.")
        return;
    }
    return;



}


'''' web handler... .ashx


Public Class ShoeHandler : Implements IHttpHandler
    
    Dim log As ILog = LogManager.GetLogger(GetType(ShoeHandler))
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        ''' ROUTE TO THE CORRECT METHOD

	   if	...code....

	   ElseIf context.Request.QueryString("Task") = "GetWhichshoe" Then
            GetWhichShoe(context, context.Request.QueryString("shoe_Number"))
           End If



    end sub

   Private Sub GetWhichshoe(ByVal context As HttpContext, ByVal var_shoeNumber As String)
        
       
        Dim var_which_shoe As String
        var_which_shoe = ""
        Dim filename As String
        filename = ""
        
        var_shoenumber = LTrim(RTrim(var_shoenumber))


        Try

            Dim dataReader As SqlDataReader
            Dim x As Integer = 0
            Dim sqlConnection As String


            Using sqlConn As New SqlConnection
                sqlConnection = "Data Source=TestshoeDB;Initial Catalog=shoes_finnish;Persist Security Info=True;User ID=ee;Password=ee"
                sqlConn.ConnectionString = sqlConnection
              

                Dim SQLstring As String = "select distinct (" & var_shoenumber & ") from shoes_Finnish_old " & _
                " where ProductID in (select ProductID from Products where shoe_leather = 'rr2111')"

                sqlConn.Open()
                Using command As New SqlCommand(SQLstring, sqlConn)
                    dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
                    If dataReader.HasRows Then
                        Do While dataReader.Read()
                            HttpContext.Current.Session("shoenumber_value") = dataReader("shoe_type_finnish_old").ToString()
                        Loop

                    End If
                    dataReader.Close()
                    sqlConn.Close()
                End Using
            End Using

        Catch ex As Exception
        Finally
        End Try

   



        ' ================================================================================
        ' _+_+_+_+_+_+_+_+_+_+_+_+
        ' 
        ' find the right wav filefor the type of shoe...


        If HttpContext.Current.Session("shoenumber_value") = 2 Then            
            var_which_shoe = 2

        End If

        If HttpContext.Current.Session("shoenumber_value") <> 2 Then
        
            var_which_shoe = 1

        End If
       
        
        context.Response.Clear()
        context.Response.ContentType = "text/xml"
        context.Response.Write(var_which_shoe)
      
    End Sub

Open in new window

Avatar of GlobaLevel
GlobaLevel
Flag of United States of America image

ASKER

I dont think I have the query string set up right..
doesnt seem that the value is being passed down to the method...

Private Sub GetWhichshoe(ByVal context As HttpContext, ByVal var_shoeNumber As String)
>>>>>>> var_shoenumber paramter is not being populated with a value...it should
Avatar of Nasir Razzaq
Do an alert to see if the value is being read

alert(shoe_number);
CodeCruiser...great idea...tried that....its not reading the value...

attached is the client/html


shouldnt one of these work?

  var shoe_number = document.getElementById(txtshoeNumber_cntrl).innerHTML;
  var shoe_number = document.getElementById(txtshoeNumber).innerHTML;
      var shoe_number = document.getElementById("<%= txtshoeNumber.ClientID %>").innerHTML;
  var shoe_number = document.getElementById(txtshoeNumber).value;
<tr>
                                                            <td class="boldgraytext">
                                                                Shoe Type :
                                                            </td>
                                                            <td class="boldbluetext">
                                                                <asp:TextBox ID="txtShoeNumber" CssClass="textboxs"  runat="server" MaxLength="30"></asp:TextBox>
                                                                <cc1:FilteredTextBoxExtender ID="ftbShoeNumber" runat="server" TargetControlID="txtShoeNumber" FilterType="Custom, Numbers" ValidChars="-SDTG" />                                                                                                                                                                                                              
                                                               
                                                            </td>
                                                        </tr>

Open in new window

I would do an alert on all of these to see if they come back as undefined or object

alert( document.getElementById(txtshoeNumber));
alert( document.getElementById('txtshoeNumber'));

Then I would try their value property rather than innerhtml.
isnt this the same thing?

var shoe_number = document.getElementById(txtshoeNumber_cntrl).innerHTML;
alert(var_shoe_number);
Have you tried what I suggested above?

okay I tried the above...

alert( document.getElementById(txtshoeNumber));
Microsoft JScript runtime error: 'txtShoeNumber' is undefined

'null'
alert( document.getElementById('txtshoeNumber'));


>>>>i hit tab and it submits the form...maybe there is an error with that...
Also....where it connects to the db....


theres a disccnnet between:
        context.Response.Clear()
        context.Response.ContentType = "text/xml"
     '''' 'this reads fine and the varaible populates as it should...
        context.Response.Write(var_which_shoe)


and here:

var xmld = load_xml("../Handler/shoe.ashx?Task=GetWhichShoe=" + shoe_number)

    if (xmld != null) {
        // Validation Completed
        // var procRetVal = getNodeValue(xmld, "retVal")

        if (xmld = 2) {
            red_shoe()
        }
        else {
            green_shoe()
        }
Basic thing is that its not reading your textbox so you need to sort that out. Also try

alert(document.getElementById("<%= txtshoeNumber.ClientID %>");
Hi CodeCruiser....

Got past that issue...thanks ...one more question if I can...once the data hits the .ashx file....and the paramter there just fine...now its not returning the value that it pulls fromthe DB...back via XML...right here:
theres a disccnnet between:
        context.Response.Clear()
        context.Response.ContentType = "text/xml"
     '''' 'this reads fine and the varaible populates as it should...
        context.Response.Write(var_which_shoe)


and here:

var xmld = load_xml("../Handler/shoe.ashx?Task=GetWhichShoe=" + shoe_number)

    if (xmld != null) {
        // Validation Completed
        // var procRetVal = getNodeValue(xmld, "retVal")

        if (xmld = 2) {
            red_shoe()
        }
        else {
            green_shoe()
        }
 
What is load_xml method?
so when it hits this...'xmld' returns null
 var xmld = load_xml("../Handler/shoe.ashx?Task=GetWhichShoe=" + shoe_number)
here it is, but I dont see where the issue is...
function load_xml(url)
{
    var loadXMLdoc;
    if (window.ActiveXObject)
    {
        loadXMLdoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    else
    {
        if (document.implementation && document.implementation.createDocument)
        {
            loadXMLdoc = document.implementation.createDocument("","",null);
        }
        else
        {
          alert('Your browser cannot use this script. Try Firefox or Opera.');
        }
    }
    
    loadXMLdoc.async = false;
    try
    {
        var loadXMLdocRetVal = loadXMLdoc.load(url);
        if (loadXMLdocRetVal == true)
        {
            //window.open(url);
            if (loadXMLdoc.documentElement != null && loadXMLdoc.documentElement.hasChildNodes())
            {
                return(loadXMLdoc);
            }
            else
            {
                return(null);
            }            
        }
    }
    catch(err)
    {
        alert('load_xml ERROR [' + err.description + ']');
    }
    return(null);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial