��权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>javascript - get_postBackElement() is always undefined - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - get_postBackElement() is always undefined - Stack Overflow

programmeradmin3浏览0评论
<asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    function BeginRequestHandler(sender, args) {
        var elem = args.get_postBackElement();
        alert("begin " + elem.value);
    }
    function EndRequestHandler(sender, args) {
        alert("end request handler");
    }
</script>

This is my simple attempt to retrieve the postback element, triggered from my UpdatePanel. My update panel looks like this:

            <asp:UpdatePanel ID="UpdatePanel_Project" UpdateMode="Conditional" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="DropDownList_Project" runat="server">
                    </asp:DropDownList>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="DropDownList_Customer" />
                </Triggers>
            </asp:UpdatePanel>

I believe I have did everything correctly...

Any ideas?

<asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    function BeginRequestHandler(sender, args) {
        var elem = args.get_postBackElement();
        alert("begin " + elem.value);
    }
    function EndRequestHandler(sender, args) {
        alert("end request handler");
    }
</script>

This is my simple attempt to retrieve the postback element, triggered from my UpdatePanel. My update panel looks like this:

            <asp:UpdatePanel ID="UpdatePanel_Project" UpdateMode="Conditional" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="DropDownList_Project" runat="server">
                    </asp:DropDownList>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="DropDownList_Customer" />
                </Triggers>
            </asp:UpdatePanel>

I believe I have did everything correctly...

Any ideas?

Share Improve this question asked Aug 17, 2011 at 11:39 KristianBKristianB 1,4434 gold badges25 silver badges46 bronze badges 5
  • 1 To help verify, could you debug and see from the server what Request.Form["__EVENTTARGET"] is? – Brian Mains Commented Aug 17, 2011 at 12:08
  • I am having this exact same problem. Did you ever find a resolution? – personaelit Commented Apr 26, 2012 at 1:43
  • @Jim - I didn't find an ASP.NET solution to this, as I hoped. I went with jQuery all the way (for that functionality). – KristianB Commented Apr 26, 2012 at 7:01
  • @Jim The problem still exists in Microsoft's code. Please view my below answer. – Ashraf Sabry Commented Dec 22, 2013 at 11:12
  • @AshrafSabry Since Microsoft isn't going to fix their bug, my answer is the only way to use ClientIDMode="Static" without postback issues. – Brad Bamford Commented Feb 7, 2015 at 23:01
Add a ment  | 

3 Answers 3

Reset to default 4

You have to set the ClientIDMode property value of the control (the DropDownList_Customer drop down list in this case) to AutoID. Please view my reply here.

What is your postback trigger ? This control seems to be missing DropDownList_Customer

 <asp:AsyncPostBackTrigger ControlID="DropDownList_Customer" />

I finally solved this pain, here's my solution.

Basically we just need to override Microsoft's _uniqueIDToClientID function so it doesn't ignore our Static client Ids on postback elements.

You'll just need to add the following code at the bottom of your page.

if (Sys.WebForms.PageRequestManager) {
  var prm = Sys.WebForms.PageRequestManager.getInstance();

  prm._uniqueIDToClientID = function (uniqueID) {
    var clientID = uniqueID.replace(/\$/g, "_");
    if (document.getElementById(clientID)) {
      return clientID;
    }

    var lastDollar = uniqueID.lastIndexOf("$");
    if (lastDollar === -1) {
      return clientID;
    }

    if (lastDollar+1 > uniqueID.length) {
      return clientID;
    }

    var staticID = uniqueID.slice(lastDollar + 1);

    return document.getElementById(staticID) ? staticID : clientID;
  };
}

Now, get_postBackElement() in your BeginRequestHandler will no longer be undefined!

Just make sure our code is executed after Microsoft's MicrosoftAjaxWebForms.js because we are overriding its _uniqueIDToClientID function.

Note: My function always returns the default WebForms ClientID if the element exists on the page. Only if the element cannot be found on the page, does it check to see if an element with a static ID exists on the page. If it exists, the staticID is used, otherwise it defaults back to the default WebForms ClientID.

发布评论

评论列表(0)

  1. 暂无评论