如何在vb.net代码中编写Java脚本? [英] How to write java script in vb.net code?

查看:85
本文介绍了如何在vb.net代码中编写Java脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人需要我帮忙吗,因为我需要用vb.net代码编写Javascript? 我的意思是我是vb.net编码的新手,我有一个通过Web服务动态创建的表,为此表我需要添加javascript代码中的排序功能,我需要将此脚本添加到动态创建表 我尝试了这个:

Can anyone help me out as I need to write a Javascript in vb.net code? what i meant is i am new to vb.net coding, I have a dynamically created table from a web-service, and for that table i need to add sorting function which is in the javascript code, i need to add this script to the dynamically created table I tried with this:

     oSB.Append("table.RegisterStartupScript('SCRIPTNAME', '<script language='javascript'>function tname(){alert('kk')};</script>')")

但它似乎根本无法正常工作.

but it seems to be not working atall.

我也尝试过这个

     'oSB.Append("<script>$('[id^=tname] th').live('click',function(event){ alert('hello')}</script>")

我的Ajax函数:

     $.ajax({
        type: "POST",
        url: "Service1.asmx/GetRecipie",
        contentType: "application/json; charset=utf-8",

        data: "{'sDB':'" + sDB + "'}",
        dataType: "json",
        success: OnGetMemberSuccess,

        failure: function (errMsg) {
            $('#errorMessage').text(errMsg);  //errorMessage is id of the  div
        }

    });
    function OnGetMemberSuccess(data, status) {

        xistr = data.d.split(',');
        $("#MemberDetails").html(data.d);
        $('input[type=button]').attr('disabled', false);
    }

} 

表是通过以下代码创建的(网络服务):

Table is created by this code(webservice):

     oSB.Append("<table id= '" + table_id + "' class='sortable' ><thead><tr><th class=border id='tname' >" + "Name" + "<img src='next.gif'/></th><th class=border>" + "Duration" + "</th><th class=border>" + "State" + "</th><th class=border>" + "Party" + "</th><th class=border>" + "Year" + "</th></tr></thead>")
     sNameValue = dr("sName").ToString
        sDurValue = dr("sDuration").ToString
        sStateValue = dr("sState").ToString
        sPartyValue = dr("sParty").ToString
        sYearValue = dr("sYear").ToString
        oSB.Append("<tbody id=tbodyid'>")
        ' oSB.Append("<tr id='trid'>")
        oSB.Append("<tr>")
        oSB.Append("<td id='tdid' class=border1>")
        oSB.Append(sNameValue)
        oSB.Append("</td>")

        oSB.Append("<td class=border1>")
        oSB.Append(sDurValue)
        oSB.Append("</td>")

        oSB.Append("<td id='td_state' class=border1>")
        oSB.Append(sStateValue)
        oSB.Append("</td>")

        oSB.Append("<td class=border1>")
        oSB.Append(sPartyValue)
        oSB.Append("</td>")

        oSB.Append("<td class=border1>")
        oSB.Append(sYearValue)
        oSB.Append("</td>")

        oSB.Append("</tr>")
        oSB.Append("</tbody>")
    End While
    dr.Close()
    con.Close()
    oSB.Append("</table>")
    'MsgBox(table.ToString)
    Debug.Print(oSB.ToString)

有人可以告诉我我错了吗?

can somebody tell me where i am wrong?

再次欢呼

推荐答案

您不能直接在vb.net代码中编写javascript.但是,您可以从vb.net代码注册并触发javascript.

you can not write javascript directly in vb.net code. However you can register and fire javascript from vb.net code.

尝试一下

Page.RegisterClientScriptBlock("key","<script>alert('Hello World');</script>");

尝试使用此vb代码块:

Try this vb code block:

Dim strScript As String = "<script>"
strScript += "alert('Hello, Pavan');"
strScript += "</script>"
Page.RegisterClientScriptBlock("strScript", strScript)

这篇关于如何在vb.net代码中编写Java脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆