GlobaLevel
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...
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
ASKER
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
Private Sub GetWhichshoe(ByVal context As HttpContext, ByVal var_shoeNumber As String)
>>>>>>> var_shoenumber paramter is not being populated with a value...it should
Do an alert to see if the value is being read
alert(shoe_number);
alert(shoe_number);
ASKER
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(tx tshoeNumbe r_cntrl).i nnerHTML;
var shoe_number = document.getElementById(tx tshoeNumbe r).innerHT ML;
var shoe_number = document.getElementById("< %= txtshoeNumber.ClientID %>").innerHTML;
var shoe_number = document.getElementById(tx tshoeNumbe r).value;
attached is the client/html
shouldnt one of these work?
var shoe_number = document.getElementById(tx
var shoe_number = document.getElementById(tx
var shoe_number = document.getElementById("<
var shoe_number = document.getElementById(tx
<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>
I would do an alert on all of these to see if they come back as undefined or object
alert( document.getElementById(tx tshoeNumbe r));
alert( document.getElementById('t xtshoeNumb er'));
Then I would try their value property rather than innerhtml.
alert( document.getElementById(tx
alert( document.getElementById('t
Then I would try their value property rather than innerhtml.
ASKER
isnt this the same thing?
var shoe_number = document.getElementById(tx tshoeNumbe r_cntrl).i nnerHTML;
alert(var_shoe_number);
var shoe_number = document.getElementById(tx
alert(var_shoe_number);
Have you tried what I suggested above?
ASKER
okay I tried the above...
alert( document.getElementById(tx
Microsoft JScript runtime error: 'txtShoeNumber' is undefined
'null'
alert( document.getElementById('t
>>>>i hit tab and it submits the form...maybe there is an error with that...
ASKER
Also....where it connects to the db....
theres a disccnnet between:
context.Response.Clear()
context.Response.ContentTy pe = "text/xml"
'''' 'this reads fine and the varaible populates as it should...
context.Response.Write(var _which_sho e)
and here:
var xmld = load_xml("../Handler/shoe. ashx?Task= GetWhichSh oe=" + shoe_number)
if (xmld != null) {
// Validation Completed
// var procRetVal = getNodeValue(xmld, "retVal")
if (xmld = 2) {
red_shoe()
}
else {
green_shoe()
}
theres a disccnnet between:
context.Response.Clear()
context.Response.ContentTy
'''' 'this reads fine and the varaible populates as it should...
context.Response.Write(var
and here:
var xmld = load_xml("../Handler/shoe.
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.getElementB yId("<%= txtshoeNumber.ClientID %>");
alert(document.getElementB
ASKER
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.ContentTy pe = "text/xml"
'''' 'this reads fine and the varaible populates as it should...
context.Response.Write(var _which_sho e)
and here:
var xmld = load_xml("../Handler/shoe. ashx?Task= GetWhichSh oe=" + shoe_number)
if (xmld != null) {
// Validation Completed
// var procRetVal = getNodeValue(xmld, "retVal")
if (xmld = 2) {
red_shoe()
}
else {
green_shoe()
}
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.ContentTy
'''' 'this reads fine and the varaible populates as it should...
context.Response.Write(var
and here:
var xmld = load_xml("../Handler/shoe.
if (xmld != null) {
// Validation Completed
// var procRetVal = getNodeValue(xmld, "retVal")
if (xmld = 2) {
red_shoe()
}
else {
green_shoe()
}
What is load_xml method?
ASKER
so when it hits this...'xmld' returns null
var xmld = load_xml("../Handler/shoe. ashx?Task= GetWhichSh oe=" + shoe_number)
var xmld = load_xml("../Handler/shoe.
ASKER
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);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER