1

我创建了函数,它会在.net 中添加评论时显示类似 twitter 的消息,当从 aspx 文件调用 javascript 函数时一切正常,但是当尝试在页面上注册它时它不起作用?

vb 中的函数:

 Dim script As String = ""
        script &= "  function ErrorMessage121212(TextClass, Error, MainDiv) { "
        script &= "     MainDiv = '#' + MainDiv;"
        script &= "      $(MainDiv).append(""<div align='center' id='overlaytext' style='margin-top:10px'></div>"");"
        script &= "    $(MainDiv).css('color', 'white');"
        script &= "      $(MainDiv).css('align', 'center');"
        script &= "       $(MainDiv).css('backgroundColor', 'black');"
        script &= "       $(MainDiv).css('display', ""none"");"
        script &= "      $('#overlaytext').html(""<b>"" + Error + ""</b>"");"
        script &= "         if (TextClass == """") {"
        script &= "          }"
        script &= "      else { "
        script &= "     $('#overlaytext').addClass(TextClass);"
        script &= "                 }"
        script &= "    $(MainDiv).fadeIn(1000, function () { $(MainDiv).fadeOut(1000); })"
        script &= "     }"
        script &= " ErrorMessage121212('" & MessageCss & "','" & errormessage & "','" & DivID & "');"
        If Not Page.ClientScript.IsClientScriptBlockRegistered("s1") Then
          Page.ClientScript.RegisterClientScriptBlock(_page.GetType(), "s1", script)
        End If
        Return True
4

2 回答 2

2

尝试使用:

ScriptManager.RegisterStartupScript(_page, typeof(Page), Guid.NewGuid().ToString(), "alert('a');", true);
于 2012-11-29T07:25:01.450 回答
1

试试下面的代码它工作正常: -

Dim script As String = ""
    script &= "  function ErrorMessage121212(TextClass, Error, MainDiv) { "
    script &= "     MainDiv = '#' + MainDiv;"
    script &= "      $(MainDiv).append(""<div align='center' id='overlaytext' style='margin-top:10px'></div>"");"
    script &= "    $(MainDiv).css('color', 'white');"
    script &= "      $(MainDiv).css('align', 'center');"
    script &= "       $(MainDiv).css('backgroundColor', 'black');"
    script &= "       $(MainDiv).css('display', ""none"");"
    script &= "      $('#overlaytext').html(""<b>"" + Error + ""</b>"");"
    script &= "         if (TextClass == """") {"
    script &= "          }"
    script &= "      else { "
    script &= "     $('#overlaytext').addClass(TextClass);"
    script &= "                 }"
    script &= "    $(MainDiv).fadeIn(1000, function () { $(MainDiv).fadeOut(1000); })"
    script &= "     }"
    script &= " ErrorMessage121212('" & MessageCss & "','" & errormessage & "','" & DivID & "');"
    If Not Page.ClientScript.IsClientScriptBlockRegistered("s1") Then
        ScriptManager.RegisterStartupScript(_page, _page.GetType, "s1", script, True)
          End If
    Return True
于 2012-11-29T08:31:53.810 回答