javascript代码不支持,linkbutton不支持回发 [英] javascript code not support , linkbutton not working on postback

查看:129
本文介绍了javascript代码不支持,linkbutton不支持回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

linkbutton点击不在firefox中工作,plz帮帮我



linkbutton click not working in firefox, plz help me out

<script type="text/javascript">
     var aClick = "false";
     var f5key = 116;
     var loc = window.location;
     $(document).bind('keydown', function (evt) {
         if (evt.which == f5key) {
             aClick = "true";
             window.form1.submit();}});

 </script>
</head>
 <body  onload="timer()" onbeforeunload="fun('notpostback',event)">
    <form id="form1" runat="server" onsubmit="fun('postback',event)">
    <asp:ScriptManager ID="scriptmanager2" runat="server" EnablePageMethods="True">
    </asp:ScriptManager>




<div>
                       <asp:GridView ID="gv1" DataKeyNames="id" runat="server" AutoGenerateColumns="false"

                        CssClass="grid_table2" BackColor="white" GridLines="both" CellPadding="0" CellSpacing="0"

                        Width="100%" OnRowCommand="gv1_OnRowCommand" OnRowDeleting="gv1_OnRowDeleting">
                        <HeaderStyle HorizontalAlign="Left" BackColor="#d4d4d4" Height="40" />
                        <AlternatingRowStyle HorizontalAlign="Left" />
                        <RowStyle HorizontalAlign="Left" />
                        <Columns>
                            <asp:TemplateField HeaderText="News">
                                <ItemTemplate>
                                    <div><%#Eval("news")%></div>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Date" DataField="datetime" />
                            <asp:TemplateField HeaderText="Action">
                                <ItemTemplate><span title="Edit" class="tooltip2">
                                    <asp:LinkButton ID="lbedit" runat="server"   CssClass="icon-edit icon" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"

                                        CommandName="alter"></asp:LinkButton></span> <span title="Delete" class="tooltip2">
                                    <asp:LinkButton ID="lbdelete" runat="server"    CssClass="icon-trash icon" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"

                                        CommandName="delete"></asp:LinkButton></span>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                        </div>







<script type="text/javascript">

           $(document).ready(function () {
               var Anchors = document.getElementsByTagName("a");
               for (var i = 0; i < Anchors.length; i++) {

                       Anchors[i].onclick = function () {
                           aClick = "true";

                   }
               }
           });


           function fun(data, event) {
               if (data == "postback") {
                   window.onbeforeunload = function () { }
               }
               else if (data == "notpostback") {
                   if (aClick == "false") {
                       ajaxCall();
                       alert("Logged Out");
                       return true;
                   }
               }
           }

           function ajaxCall() {
               jQuery.ajax({
                   url: 'ManageNews.aspx/Logout',
                   type: "POST",
                   data: "{}",
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: function (data) {
                       window.location.href = "Login";
                   }
               });
               return true;
           }
           function timer() {
               setTimeout(function () { ajaxCall(); }, 1200000);
           }
    </script>

推荐答案

(文件).bind('keydown',function(evt){
if(evt.which == f5key){
aClick =true;
window.form1.submit();}});

< / script >
< / head >
< body onload = timer() onbeforeunload < span class =code-keyword> = fun('notpostback',event) >
< 表格 id = form1 runat = server onsubmit = fun('postback',event) >
< asp:ScriptManager ID = scriptmanager2 runat = 服务器 EnablePageMethods = True >
< / asp:ScriptManager >
(document).bind('keydown', function (evt) { if (evt.which == f5key) { aClick = "true"; window.form1.submit();}}); </script> </head> <body onload="timer()" onbeforeunload="fun('notpostback',event)"> <form id="form1" runat="server" onsubmit="fun('postback',event)"> <asp:ScriptManager ID="scriptmanager2" runat="server" EnablePageMethods="True"> </asp:ScriptManager>




<div>
                       <asp:GridView ID="gv1" DataKeyNames="id" runat="server" AutoGenerateColumns="false"

                        CssClass="grid_table2" BackColor="white" GridLines="both" CellPadding="0" CellSpacing="0"

                        Width="100%" OnRowCommand="gv1_OnRowCommand" OnRowDeleting="gv1_OnRowDeleting">
                        <HeaderStyle HorizontalAlign="Left" BackColor="#d4d4d4" Height="40" />
                        <AlternatingRowStyle HorizontalAlign="Left" />
                        <RowStyle HorizontalAlign="Left" />
                        <Columns>
                            <asp:TemplateField HeaderText="News">
                                <ItemTemplate>
                                    <div><%#Eval("news")%></div>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Date" DataField="datetime" />
                            <asp:TemplateField HeaderText="Action">
                                <ItemTemplate><span title="Edit" class="tooltip2">
                                    <asp:LinkButton ID="lbedit" runat="server"   CssClass="icon-edit icon" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"

                                        CommandName="alter"></asp:LinkButton></span> <span title="Delete" class="tooltip2">
                                    <asp:LinkButton ID="lbdelete" runat="server"    CssClass="icon-trash icon" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"

                                        CommandName="delete"></asp:LinkButton></span>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                        </div>







<script type="text/javascript">


(document).ready(function () {
var Anchors = document.getElementsByTagName(\"a\");
for (var i = 0; i < Anchors.length; i++) {

Anchors[i].onclick = function () {
aClick = \"true\";

}
}
});


function fun(data, event) {
if (data == \"postback\") {
window.onbeforeunload = function () { }
}
else if (data == \"notpostback\") {
if (aClick == \"false\") {
ajaxCall();
alert(\"Logged Out\");
return true;
}
}
}

function ajaxCall() {
jQuery.ajax({
url: 'ManageNews.aspx/Logout',
type: \"POST\",
data: \"{}\",
contentType: \"application/json; charset=utf-8\",
dataType: \"json\",
success: function (data) {
window.location.href = \"Login\";
}
});
return true ;
}
function timer() {
setTimeout(function () { ajaxCall(); }, 1200000);
}
</script>
(document).ready(function () { var Anchors = document.getElementsByTagName("a"); for (var i = 0; i < Anchors.length; i++) { Anchors[i].onclick = function () { aClick = "true"; } } }); function fun(data, event) { if (data == "postback") { window.onbeforeunload = function () { } } else if (data == "notpostback") { if (aClick == "false") { ajaxCall(); alert("Logged Out"); return true; } } } function ajaxCall() { jQuery.ajax({ url: 'ManageNews.aspx/Logout', type: "POST", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { window.location.href = "Login"; } }); return true; } function timer() { setTimeout(function () { ajaxCall(); }, 1200000); } </script>


in order to call the java script function to work on linkbutton click you need to add OnClientClick or u need to remove the runat=\"server\" from the existing code because these are server side code and on click postback occurs.
in order to call the java script function to work on linkbutton click you need to add OnClientClick or u need to remove the runat="server" from the existing code because these are server side code and on click postback occurs.


这篇关于javascript代码不支持,linkbutton不支持回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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