Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

this works very well. But when I insert asp:TreeView on the webpage...
XML
<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>


... 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
XML
<%@ 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

>
Posted
Updated 31-Aug-10 2:01am
v3

1 solution

__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.
 
Share this answer
 
v2
Comments
Venkatesh Mookkan 31-Aug-10 7:32am    
Answer has been updated.
Doriath21 31-Aug-10 7:33am    
Ofcourse...when I point with my mouse to the treenodes the javascript-command is displayed on bottom of my browser(firefox). And __doPostBack() is fired correctly for all controls until I insert the asp:TreeView-control. So there musst be something generated that blocks my _doPostBack?!
Venkatesh Mookkan 31-Aug-10 7:35am    
Just try adding a TreeView control in a sample website and repeat the scenario and let me know.
Doriath21 31-Aug-10 7:59am    
I've added my sample above

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900