admin管理员组文章数量:1426642
I want to pass a parameter to a JavaScript function to use in document.getElementByID() as follows:
function PrinGridView(GridViewname)
{
var TableRow= document.getElementByID("GridViewname").getElementsBytagName("tr");
var td= TableRow.item(0).getElementsBytagName("th");
if(td.length>0)
alert('done');
}
In my asp page, I have an image button event:
onClicke="PrinGridView("<%=MyGrideView.ClientID%>")";
but it does not work well.
How can I pass the GridView to a function?
Thanks.
I want to pass a parameter to a JavaScript function to use in document.getElementByID() as follows:
function PrinGridView(GridViewname)
{
var TableRow= document.getElementByID("GridViewname").getElementsBytagName("tr");
var td= TableRow.item(0).getElementsBytagName("th");
if(td.length>0)
alert('done');
}
In my asp page, I have an image button event:
onClicke="PrinGridView("<%=MyGrideView.ClientID%>")";
but it does not work well.
How can I pass the GridView to a function?
Thanks.
Share Improve this question edited Oct 4, 2020 at 8:42 Overwatch 391 silver badge8 bronze badges asked Mar 26, 2013 at 11:30 SamerKourSamerKour 251 gold badge2 silver badges4 bronze badges 1-
In
document.getElementByID("GridViewname")
,GridViewName
shouldn't be in quotes – Basic Commented Mar 26, 2013 at 11:53
4 Answers
Reset to default 3Javascript is case sensitive; it's getElementById
not getElementByID
, getElementsByTagName
not getElementsBytagName
etc.
There are other typos; F12 in your browser and the Error/Console will display script errors.
You need to mix quotes as the below is not valid, aside from the typo its not a parseable string as the quotes are broken:
onClicke="PrinGridView("<%=MyGrideView.ClientID%>")";
Change to
onClick="PrinGridView('<%=MyGrideView.ClientID%>')";
Within the function you quote what should probably be the argument, change from
var TableRow = document.getElementByID("GridViewname")
to
var TableRow= document.getElementById(GridViewname)
You have a typo there, onClicke. This is wrong, should be onClick.
Try like this
onClick="PrinGridView(this)"
function PrinGridView(obj)
{
var gridName = obj.id;
var TableRow= document.getElementByID(gridName).getElementsBytagName("tr");
var td= TableRow.item(0).getElementsBytagName("th");
if(td.length>0)
alert('done');
}
this works perfectly for inline code
OnClientClick='<%#String.Format("buttonstatus(""{0}"",""{1}"",""{2}"",""{3}"");return false;", Eval("listingid"), "D", "Archived", Eval("EndDate"))%>'
本文标签: pass parameter to javascript function in aspnet PageStack Overflow
版权声明:本文标题:pass parameter to javascript function in asp.net Page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745462052a2659367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论