从后面的代码中调用javascript函数 [英] Calling javascript function from code behind

查看:61
本文介绍了从后面的代码中调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个帐户设置页面,用户可以在其中更改公司名称,管理员密码或主密码.我正在使用javascript和链接.当用户单击更改管理员密码"链接时,将调用javascript代码,并将相应的"div"设置为style.display = inline(否则,其始终为style.display = none).设置密码后,用户单击保存密码"(一个按钮).这导致回发,因此可见的"div"被隐藏.

我正在尝试在page_load上调用一个javascript函数来检查用户是否正在使用管理员密码,它应该显示它,即set style.display = inline ...但是我无法做到这一点.我正在使用的代码被称为一次,但不是在每个回发中.请帮助:

这是我的代码,用于在page_load
上调用javascript函数

 如果(不是 ClientScript.IsStartupScriptRegistered(  viewdiv")). GetType (),"  viewdiv" ;,   view('divAdminPassword'); "结束 如果 



而我的javascript函数是:

功能视图(obj)
     {
          var  div = document.getElementById(obj);


                div.style.display = " ;

    } 

解决方案

CP VB/C# Javascript文章


首先从上面的主题的一些背景知识开始阅读CodeProject文章


这真的很奇怪

我在一个aspx文件中有以下代码

 链接 As  字符串 = " & ViewState.Item(" )
                           如果(不是 ClientScript.IsStartupScriptRegistered("  OpenPage"))). GetType (),"  OpenPage"  window.open('"& link& " )

                           结束 如果 


它设法使用url
打开一个新窗口
当我尝试在其他页面上使用相同的脚本时,它不起作用!
可能是什么问题?


 page.clientscript.registerscriptblock(. gettype ()," "  


I have an account settings page where the user can change the company name, admin password or main password. I am using javascript and links. When user click the "change admin password" link, the javascript code is called and the appropriate "div" is set to style.display=inline (otherwise its always style.display=none). After setting the password, the user clicks "Save Password" (a button). This causes a postback and so the visible "div" gets hidden.

I am trying to call a javascript function on page_load to check if the user was working on the admin password, it should display it i.e set style.display=inline... however i am unable to do that. The code i am using just gets called ONCE but not on every postback. Kindly help:

Here is my code for calling the javascript function on page_load


If (Not ClientScript.IsStartupScriptRegistered("viewdiv")) Then

                Page.ClientScript.RegisterStartupScript _
(Me.GetType(), "viewdiv";, "view('divAdminPassword');", True)
            End If



And my javascript function is:

function view(obj)
     {
         var div = document.getElementById(obj);


                div.style.display = "inline";

    }

解决方案

CP VB / C# Javascript Article


Start with some background reading on the subject above is a CodeProject Article


this is really strange

i have the following code in one aspx file

Dim link As String = "collection.aspx?SettleID=" & ViewState.Item("SettleID")
                           If (Not ClientScript.IsStartupScriptRegistered("OpenPage")) Then

                               Page.ClientScript.RegisterStartupScript _
                                                   (Me.GetType(), "OpenPage", "window.open('" & link & "');", True)

                           End If


it manages to open a new window with the url

when i try to use the same script on other pages, it does not work!
what could be the issue?


page.clientscript.registerscriptblock(me.gettype(),"alert","alert('Invalid username',true)"


这篇关于从后面的代码中调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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