TreeView阻止__doPostback!? [英] TreeView blocks __doPostback !?

查看:62
本文介绍了TreeView阻止__doPostback!?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我对asp:TreeView-Control有问题.我有一个网站,但我使用javascriptfuction"__doPostPack"来获取有关被单击的ui元素的信息.

Hi all

I have a problem with the asp:TreeView-Control. I have a website wehre I use the javascriptfuction "__doPostPack" do get information about the ui-element that was clicked

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}


这很好.但是当我在网页上插入asp:TreeView时...


this works very well. But when I insert asp:TreeView on the webpage...

<asp:TreeView runat="server" ImageSet="Arrows" NodeIndent="0" OnTreeNodePopulate="Node_Populate">
    <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
    <Nodes>
    <asp:TreeNode Text="Module und Dialoge" Value="0" PopulateOnDemand="true" SelectAction="None"/>
    </Nodes>
    <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" />
</asp:TreeView>



... ...现在似乎不再为该网页上的每个控件触发__doPostPack了,因为每次__EVENTTARGET和__EVENTARGUMENT都清除了.
有人知道这个问题吗?


伊迪丝:完整代码



... already now the __doPostPack seems not to be fired anymore for every control on this webpage because every time __EVENTTARGET and __EVENTARGUMENT is clear.
Does anybody know something about this problem?


Edith: Complete code

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Web_Lokalisierung.Models.EditNewViewModel>" %>
<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
    JOMOsoft M Lokalisierung
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Bearbeitung [<%=ViewData["Slave"] %>]</h2>
    <asp:Panel ID="Panel2" runat="server" BackColor="LightGray" HorizontalAlign="Right">
        <%=Html.ActionLink("[zurück]","Chose")%>
    </asp:Panel>
    <form id="Form1" runat="server">
    <div class="aspNetHidden">
        <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
        <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
        <input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE0MjA5MTc2MzVkZM2XOunXa05eDa/N53CJ2xekpEBT4Wcm0UB2FrQijzS/" />
        <input type="hidden" name="__MASTER" id="Hidden1" value="<%=ViewData["Master"] %>" />
        <input type="hidden" name="__SLAVE" id="Hidden2" value="<%=ViewData["Slave"] %>" />
        <input type="hidden" name="__FOCUS" id="Hidden3" value="<%=ViewData["Focus"] %>" />
        <input type="hidden" name="__FILTER" id="Hidden4" value="<%=ViewData["Filter"] %>" />
    </div>
<script type="text/javascript">
//<![CDATA[
        window.onload = function () {
            var strCook = document.cookie;
            if (strCook.indexOf("!~") != 0) {
                var intS = strCook.indexOf("!~");
                var intE = strCook.indexOf("~!");
                var strPosList = strCook.substring(intS + 2, intE);
                var strPosTree = strCook.substring(intS + 2, intE);
                document.getElementById("listDiv").scrollTop = strPosList;
                document.getElementById("treeDiv").scrollTop = strPosTree;
            }
        }
        window.onunload = function () {
            var intYList = document.getElementById("listDiv").scrollTop;
            var intYTree = document.getElementById("treeDiv").scrollTop;
            document.cookie = "yPos=!~" + intYList + "~!";
            document.cookie = "yPos=!~" + intYTree + "~!";
        }
        var theForm = document.forms['Form1'];
        if (!theForm) {
            theForm = document.Form1;
        }
        function __doPostBack(eventTarget, eventArgument) {
            if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
                theForm.__EVENTTARGET.value = eventTarget;
                theForm.__EVENTARGUMENT.value = eventArgument;
                theForm.submit();
            }
        }
//]]>
</script>
<script runat="server">
        void Node_Populate(object sender, System.Web.UI.WebControls.TreeNodeEventArgs e)
        {
            if (e.Node.ChildNodes.Count == 0)
            {
                switch (e.Node.Depth)
                {
                    case 0:
                        FillModules(e.Node);
                        break;
                    case 1:
                        FillDialoges(e.Node);
                        break;
                }
            }
        }
        void FillModules(TreeNode node)
        {
            string modul = String.Empty;
            foreach (Web_Lokalisierung.Models.ModulDialogObject item in Model.TreeViewData)
            {
                if (modul != item.ModulName)
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Text = item.ModulName;
                    newNode.Value = item.ModulName;
                    newNode.PopulateOnDemand = true;
                    newNode.SelectAction = TreeNodeSelectAction.Select;
                    node.ChildNodes.Add(newNode);
                }
                modul = item.ModulName;
            }
        }
        void FillDialoges(TreeNode node)
        {
            foreach (Web_Lokalisierung.Models.ModulDialogObject item in Model.TreeViewData)
            {
                if (item.ModulName == node.Value)
                {
                    if (item.DialogName != String.Empty)
                    {
                        TreeNode newNode = new TreeNode();
                        newNode.Text = item.DialogName;
                        newNode.Value = item.ModulName + "_" + item.DialogName;
                        newNode.PopulateOnDemand = false;
                        newNode.SelectAction = TreeNodeSelectAction.Select;
                        node.ChildNodes.Add(newNode);
                    }
                }
            }
        }
</script>
    <asp:Table runat="server" >
        <asp:TableRow VerticalAlign="Top">
            <asp:TableCell>
                <div id="treeDiv" style="width: 190px; height: 650px; overflow-x: auto; overflow-y: auto;
                    background: #E8EEF4">
                    <asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" NodeIndent="0" OnTreeNodePopulate="Node_Populate">
                        <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                        <Nodes>
                        <asp:TreeNode Text="Module und Dialoge" Value="0" PopulateOnDemand="true" SelectAction="None" />
                        </Nodes>
                        <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" />
                    </asp:TreeView>
                </div>
                <%--<asp:Panel ID="Panel3" runat="server" BackColor="#E8EEF4" Width="180">
                </asp:Panel>--%>
            </asp:TableCell>
            <asp:TableCell>
                <div id="listDiv" style="width: 400px; height: 600px; overflow-x: auto;
                    overflow-y: auto">
                    <select size="<%=Model.UidDictionary.Count()+1 %>" name="masterList" style="min-width: 400px" id="MainContent_masterList1"

                        onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;masterList\&#39;,\&#39;\&#39;)&#39;, 0)">
                        <%foreach (KeyValuePair<string, bool> item in Model.UidDictionary)
                          {
                              if (item.Value == true)
                              {%>
                        <option <%if (item.Key == ViewData["Focus"].ToString() || Model.UidDictionary.Count()==1){ %>selected="selected"
                            <%} %> style="background-color: #dff5e6" value="<%=item.Key%>">
                            <%=item.Key%></option>
                        <%}
                              else
                              { %>
                        <option <%if (item.Key == ViewData["Focus"].ToString()|| Model.UidDictionary.Count()==1){ %>selected="selected"
                            <%} %> style="background-color: #f7d8df" value="<%=item.Key%>">
                            <%=item.Key%></option>
                        <%}
                          }%>
                    </select>
                </div>
                <asp:Table runat="server">
                    <asp:TableRow>
                        <asp:TableCell HorizontalAlign="Center" BorderColor="Transparent">
                <div style="background-color:#dff5e6;width:100px">übersetzt</div>
                        </asp:TableCell>
                        <asp:TableCell HorizontalAlign="Center" BorderColor="Transparent">
                <div style="background-color:#f7d8df;width:100px">nicht übersetzt</div>
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </asp:TableCell>
            <asp:TableCell BorderColor="Transparent" Width="800" Style="height: 600px">
    <asp:Table runat="server" >
    <asp:TableRow>
    <asp:TableCell BorderColor="Transparent" Height="40" Width="800">
    <input type="text" readonly="readonly" value="<%=ViewData["FocusUid"] %>" style="width:inherit;font-weight:bold" />
    <br />
    <input type="text" readonly="readonly" value="<%=ViewData["MasterTextProperty"] %>" style="width:200" />
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow>
    <asp:TableCell BorderColor="Transparent" Height="40" Width="800">
    <%=ViewData["master"] %>
    <br />
    <textarea name="taMaster" readonly="readonly" style="width:inherit" cols="1" rows="10"><%=ViewData["MasterText"] %></textarea>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow>
    <asp:TableCell BorderColor="Transparent" Height="40" Width="800">
    <%=ViewData["Slave"] %>
    <br />
    <textarea name="taSlave" style="width:inherit" cols="1" rows="10"><%=ViewData["SlaveText"] %></textarea>
    <br />
    <input type="submit" value="Datensatz abspeichern" style="width:inherit" />
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow Height="100" >
    <asp:TableCell  BorderColor="Transparent">
    <font color="red"><b><%=ViewData["Fail"] %></b></font>
    <font color="green"><b><%=ViewData["Sucsess"] %></b></font>
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    </form>
    <asp:Panel ID="Panel1" runat="server" BackColor="LightGray" HorizontalAlign="Right">
        <%=Html.ActionLink("[zurück]","Chose")%>
    </asp:Panel>
</asp:Content


>

推荐答案

__doPostBack() will be called only on PostBack of the page. Sounds like your page is not postbacking.

Check if all HTML tags properly closed. Just try adding a TreeView control in a sample website and repeat the scenario and let me know.
__doPostBack() will be called only on PostBack of the page. Sounds like your page is not postbacking.

Check if all HTML tags properly closed. Just try adding a TreeView control in a sample website and repeat the scenario and let me know.


这篇关于TreeView阻止__doPostback!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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