用于imagebutton的javascript [英] javascript for imagebutton
问题描述
我的javscript无法正常工作.我正在使用javascript打开一个新的弹出窗口来编辑记录,但是该窗口处于打开状态但不包含ID值.我的问题是如何使用javascript来获取imagebutton命令名值? ="HTML"> < asp:gridview > < asp:ImageButton ID =" ImageUrl =" runat =" =' <%#Container.DataItem(" )%>' 文本 = ' <%#Container.DataItem(" ID")%>' OnClientClick =" > < > 如果
不 IsPostBack 然后
Session.Add(" ,ConfigurationManager.AppSettings( " ))
如果 不是 Request.QueryString(" ID")= " 然后
ViewState.Add(" ,Request.QueryString( " ))
' LoadRecord(Request.QueryString("ID"))
ViewState.Add(" ,Session.Item( " ))
' LoadstateInfo(Request.QueryString("ID"))
结束 如果
结束 如果
< script type = " language = " >
功能 openph(str)
{
var img = 文档 .getElementById(" 编辑")
var url1 = " + img;
窗口 .open(URL1," ,"
预先感谢我认为你需要这个:
----//表示代码已更新
< 脚本 类型 =" 语言 =" JavaScript" < /script >
您可以尝试这样的操作:
< asp:gridview xmlns:asp =" < id =" 编辑" 图片网址 〜/Pages/Images/Edit_new.jpg" 运行 =" 命令名 =" <%#Container.DataItem(" ID")%>" onclientclick =" <%# Container.DataItem(" )%>)" / < /asp:gridview >
< script type = " language = " > 函数 openph(commandName){ var url1 = " + commandName; 窗口 .open(URL1," ,"
您需要像这样更改Javascript ...
您在url1中还写了"new Employee.aspx....."
在这里,如果您将该页面放置在新文件夹的旁边,则像这样
new/Employee.aspx....
或者如果您将其编写为新窗口,则无需编写它,只需使用我提供的js函数来调用您的编辑方法...
< script type = " language = " > 功能 openph(img){ var url1 = " + img.text; newWindow = 窗口 .open(url1," ,此 .target," ); 如果(newWindow.focus()){ newWindow.focus() } }
并且您需要像这样更改您的设计代码...
< asp:imagebutton id =" 图片网址 =" 〜/edit.png" 宽度 =" =" 10px" 运行 =" 命令名 =" <%#Eval(" ID")%>" 文本 =" <%#Eval(" )%>" xmlns:asp =" > OnClientClick =返回openph(this)"/> < /asp:imagebutton >
如果使用此按钮传递图像按钮,则无需执行document.getElementByID,而且操作方式也不正确,因为当您需要将该元素作为网格中的项目模板或任何其他控件贴花时,您无法直接获取该元素...
在这里,您可以在调用您的edit方法时传递此键,以便您可以将该控件直接传递给调用者函数,因此可以使用...
My javscript are not working.i am using a javascript for open a new pop window for edit a records,but window are open but not contains ID values.my question is how use javascript for get imagebutton commandname value?
<asp:gridview><asp:ImageButton ID="Edit" ImageUrl="~/Pages/Images/Edit_new.jpg" runat="server" CommandName='<%# Container.DataItem("ID") %>' text='<%# Container.DataItem("ID") %>' OnClientClick ="return openph(this)" /></asp:gridview>
If Not IsPostBack Then
Session.Add("CnString", ConfigurationManager.AppSettings("CnString"))
If Not Request.QueryString("ID") = "" Then
ViewState.Add("ID", Request.QueryString("ID"))
'LoadRecord(Request.QueryString("ID"))
ViewState.Add("RoleID", Session.Item("RoleID"))
'LoadstateInfo(Request.QueryString("ID"))
End If
End If
<script type="text/javascript" language="JavaScript">
function openph(str)
{
var img=document .getElementById ("Edit")
var url1 = "New Employee.aspx?ResponseType=Edit&Id=" + img ;
window.open(url1, "test","top=0,left=0,menubar=no,toolbar=no,location=no, resizable=no,height=550,width=440,status=no,scrollbars=no,minimizable=no,maxmizable=no,resizable=0,titlebar=no;");
if ( window .focus ())
{
url1 .focus()
}
}
</script>
advance thanks
I think u need this:
----// means the code is updated
<script type="text/javascript" language="JavaScript"> function openph(str) { ----//var img=document .getElementById ("Edit") var imgCommand=document.getElementById ("Edit").getAttribute("CommandName") ---//var url1 = "New Employee.aspx?ResponseType=Edit&Id=" + img ; var url1 = "New Employee.aspx?ResponseType=Edit&Id=" + imgCommand var newwin = window.open(url1, -------//window.open(url1, "test","top=0,left=0,menubar=no,toolbar=no,location=no, resizable=no,height=550,width=440,status=no,scrollbars=no,minimizable=no,maxmizable=no,resizable=0,titlebar=no;"); if ( newwin.focus ) ------//if ( window .focus ()) { ---//url1 .focus() newwin.focus() } } </script>
You could try something like this:
<asp:gridview xmlns:asp="#unknown"><asp:imagebutton id="Edit" imageurl="~/Pages/Images/Edit_new.jpg" runat="server" commandname="<%# Container.DataItem("ID") %>" onclientclick="return openph(<%# Container.DataItem("ID") %>)" /></asp:gridview>
<script type="text/javascript" language="JavaScript"> function openph(commandName) { var url1 = "New Employee.aspx?ResponseType=Edit&Id=" + commandName; window.open(url1, "test","top=0,left=0,menubar=no,toolbar=no,location=no, resizable=no,height=550,width=440,status=no,scrollbars=no,minimizable=no,maxmizable=no,resizable=0,titlebar=no;"); if (window .focus()) { url1.focus() } } </script>
You Need to Change your Javascript Like This...
one more thing in url1 you write"new Employee.aspx....."
here if you have that page placed in side new folder then wirte like this
new/Employee.aspx....
or if you write it for new window then no need to write it just use my provided js function to call your edit method...
<script type="text/javascript" language="JavaScript"> function openph(img) { var url1 = "Employee.aspx?ResponseType=Edit&Id=" + img.text; newWindow = window.open(url1, "test", this.target, "top=0,left=0,menubar=no,toolbar=no,location=no, resizable=no,height=550,width=440,status=no,scrollbars=no,minimizable=no,maxmizable=no,resizable=0,titlebar=no;"); if (newWindow.focus()) { newWindow.focus() } }
and you need to change your design code like this...
<asp:imagebutton id="Edit" imageurl="~/edit.png" width="10px" height="10px" runat="server" commandname="<%# Eval("ID") %>" text="<%# Eval("ID") %>" xmlns:asp="#unknown"> OnClientClick="return openph(this)" /> </asp:imagebutton>
if you pass your image button using this then no need to do document.getElementByID and also you do it in wrong way, because when you need to get the element decalred as a item template inside grid or any other control at that time you can not get that element directly...
here you pass this keywork while calling your edit method so you can get that control directly to your caller function so use that...
这篇关于用于imagebutton的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!