Newbie Needs Help With Very Basic CallBack

26 views
Skip to first unread message

HK

unread,
Feb 16, 2009, 6:32:51 PM2/16/09
to asp-ajaxed
I have a basic HTML page (no ASP or VBScript yet) with a form. The
form has one text box that takes a single search term. There is also a
submit button.

Now I want the submit button to call a server-side function that looks
something like this and display the HTML that gets returned:


Function fGetHTMLData(sSearch)

Dim con, rst, sSQL, sSQLWhere, s
Set con = Server.CreateObject("ADODB.Connection")
con.open Session("sMainDBConString")
sSQLWhere = " WHERE itemname like '%" & sSearch & "'%"
sSQL = "SELECT * FROM tblInventory" & sSQLWhere
Set rst = Server.CreateObject("ADODB.Recordset")
rst.open sSQL, con, 1, 3

If rst.EOF = False or rst.BOF = False Then
s = "<br /><table><tr>"
s = s & "<th class="item">Item</th></tr>"

rst.MoveFirst
While not rst.EOF
s = s & "<tr class=""cellcolor1"">"
s = s & "<td class=""item"">" & rst.Fields("ItemName").value & "</
td></tr>"

rst.MoveNext
Wend

s = s & "</table>"
Else
s = "No Data Found"
End If

fGetHTMLData = s

End Function



I've read through the documentation and looked through all the
tutorials but I remain very baffled as to where to start.

Michal Gabrukiewicz

unread,
Feb 16, 2009, 9:19:33 PM2/16/09
to HK, asp-ajaxed
Hi Harlan,

I would recomment having a quick read through http://www.ajaxed.org/articles/Getting-Started/ .. this helps you to get ajaxed running ..

for your specific problem you would ideally use pageparts ... (check page part section in http://www.ajaxed.org/article/AJAX/11/)

just name your function Function pagePart_fGetHTMLData() and remove its argument (you will be able to access the argument through POST variables)..
after that you will able to call it from client side ...

basically your solution would look like this

<!--#include virtual="/ajaxed/ajaxed.asp"-->
<%
set page = new AjaxedPage
page.defaultStructure = true
page.draw()

sub main() %>


<form id="frm">
<input type="text" name="q" id="q">
<button type="button" onclick="ajaxed.callback('
fGetHTMLData', 'content')">content 1</button>
</form>
<div id="content"></div>

<% end sub

sub
pagePart_fGetHTMLData()

Dim con, rst, sSQL, sSQLWhere, s

       Set con = Server.CreateObject("ADODB.Connection")
       con.open Session("sMainDBConString")
       sSQLWhere = " WHERE itemname like '%" & page.RF("q") & "'%"

       sSQL = "SELECT * FROM tblInventory" & sSQLWhere
       Set rst = Server.CreateObject("ADODB.Recordset")
       rst.open sSQL, con, 1, 3

       If rst.EOF = False or rst.BOF = False Then
               s = "<br /><table><tr>"
               s = s & "<th class="item">Item</th></tr>"

               rst.MoveFirst
               While not rst.EOF
                       s = s & "<tr class=""cellcolor1"">"
                       s = s & "<td class=""item"">" & rst.Fields("ItemName").value & "</
td></tr>"

                       rst.MoveNext
               Wend

               s = s & "</table>"
       Else
               s = "No Data Found"
       End If

       response.write(s)
end sub
%>

--
michal
Sent from: Khlong Toei Nuea Bangkok Thailand.

HK

unread,
Feb 16, 2009, 10:04:48 PM2/16/09
to mga...@gmail.com, asp-ajaxed
Thanks. That helped me out quite a bit.

Now I'm having a problem where Firefox 3.x is always showing a blank error message when I submit the search.

mga...@gmail.com

unread,
Feb 16, 2009, 10:12:07 PM2/16/09
to asp-ajaxed
try to update this

<form onsubmit="return false" id="frm">

On Feb 17, 2009 10:04am, HK <harlan...@gmail.com> wrote:
> Thanks. That helped me out quite a bit.
>
> Now I'm having a problem where Firefox 3.x is always showing a blank error message when I submit the search.
>
>
> On Mon, Feb 16, 2009 at 9:19 PM, Michal Gabrukiewicz mga...@gmail.com> wrote:
>
>
> Hi Harlan,
>
> I would recomment having a quick read through http://www.ajaxed.org/articles/Getting-Started/ .. this helps you to get ajaxed running ..
>
>
>
>
>
> for your specific problem you would ideally use pageparts ... (check page part section in http://www.ajaxed.org/article/AJAX/11/)
>
> just name your function Function pagePart_fGetHTMLData() and remove its argument (you will be able to access the argument through POST variables)..
>
>
>
>
> after that you will able to call it from client side ...
>
> basically your solution would look like this
>
> >
>
>
> set page = new AjaxedPage
> page.defaultStructure = true
> page.draw()
>
> sub main() %>
>
>
>
>
>
> button type="button" onclick="ajaxed.callback('fGetHTMLData', 'content')">content 1button>
>
>
>
>
>
> div id="content">div>
>
>
>
> end sub
>
> sub pagePart_fGetHTMLData()
>
>
>
> Dim con, rst, sSQL, sSQLWhere, s
>
>        Set con = Server.CreateObject("ADODB.Connection")
>
>
>
>        con.open Session("sMainDBConString")
>
>
>        sSQLWhere = " WHERE itemname like '%" & page.RF("q") & "'%"
>
>
>        sSQL = "SELECT * FROM tblInventory" & sSQLWhere
>
>
>        Set rst = Server.CreateObject("ADODB.Recordset")
>
>
>        rst.open sSQL, con, 1, 3
>
>
>
>
>
>        If rst.EOF = False or rst.BOF = False Then
>
>
>                s = "
> "
>
>
>                s = s & "Item"
>
>
>
>
>
>                rst.MoveFirst
>
>
>                While not rst.EOF
>
>
>                        s = s & ""
>
>
>                        s = s & "" & rst.Fields("ItemName").value & "
>
> td>"
>
>
>
>
>
>                        rst.MoveNext
>
>
>                Wend
>
>
>
>
>
>                s = s & ""
>
>
>        Else
>
>
>                s = "No Data Found"
>
>
>        End If
>
>
>
>
>
>
>        response.write(s)
>
> end sub
> %>
>
>
> On Tue, Feb 17, 2009 at 6:32 AM, HK Harlan...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
> I have a basic HTML page (no ASP or VBScript yet) with a form. The
>
>
> form has one text box that takes a single search term. There is also a
>
>
> submit button.
>
>
>
>
>
> Now I want the submit button to call a server-side function that looks
>
>
> something like this and display the HTML that gets returned:
>
>
>
>
>
>
>
>
> Function fGetHTMLData(sSearch)
>
>
>
>
>
>        Dim con, rst, sSQL, sSQLWhere, s
>
>
>        Set con = Server.CreateObject("ADODB.Connection")
>
>
>        con.open Session("sMainDBConString")
>
>
>        sSQLWhere = " WHERE itemname like '%" & sSearch & "'%"
>
>
>        sSQL = "SELECT * FROM tblInventory" & sSQLWhere
>
>
>        Set rst = Server.CreateObject("ADODB.Recordset")
>
>
>        rst.open sSQL, con, 1, 3
>
>
>
>
>
>        If rst.EOF = False or rst.BOF = False Then
>
>
>                s = "
> "
>
>
>                s = s & "Item"
>
>
>
>
>
>                rst.MoveFirst
>
>
>                While not rst.EOF
>
>
>                        s = s & ""
>
>
>                        s = s & "" & rst.Fields("ItemName").value & "
>
> td>"
>
>
>
>
>
>                        rst.MoveNext
>
>
>                Wend
>
>
>
>
>
>                s = s & ""
>
>

HK

unread,
Feb 16, 2009, 10:14:07 PM2/16/09
to mga...@gmail.com, asp-ajaxed
Update: It looks like firefox is bombing out on the following:

  dispatchException: function(exception) {
(this.options.onException || Prototype.emptyFunction)(this, exception);
Ajax.Responders.dispatch('onException', this, exception);
}
});



On Mon, Feb 16, 2009 at 9:19 PM, Michal Gabrukiewicz <mga...@gmail.com> wrote:

HK

unread,
Feb 16, 2009, 10:17:38 PM2/16/09
to asp-ajaxed
Looks like that solved it. Thanks

On Feb 16, 10:12 pm, mga...@gmail.com wrote:
> try to update this
>
> <form onsubmit="return false" id="frm">
>
> On Feb 17, 2009 10:04am, HK <harlan.ko...@gmail.com> wrote:> Thanks. That helped me out quite a bit.
>
> > Now I'm having a problem where Firefox 3.x is always showing a blank  
>
> error message when I submit the search.
>
> > On Mon, Feb 16, 2009 at 9:19 PM, Michal Gabrukiewicz mga...@gmail.com>  
> wrote:
>
> > Hi Harlan,
>
> > I would recomment having a quick read through  
>
> http://www.ajaxed.org/articles/Getting-Started/.. this helps you to get  
> ajaxed running ..
>
> > for your specific problem you would ideally use pageparts ... (check page  
>
> part section inhttp://www.ajaxed.org/article/AJAX/11/)
Reply all
Reply to author
Forward
0 new messages