Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Stop post back for certain <div>'s

Wonder if you guys can help me?

I'm using ASP.NET/C#/VS2005.

I have a master page with 3 <div>'s

header
menu
content

the menu <div> has a treemenu (not VS treemenu), its all done in JS. When a user clicks on a menu it will open up and display submenus, and they can click on any of the hrefs.

My problem is when someone clicks on any of the submenu links, it does a post_back, and because of that, it refreshes the whole screen, so the menu is collapsed. Is there a way to stop a post back on the menu <div>?

Thanks, and I hope that makes sense?
Mousemat24
0
mousemat24
Asked:
mousemat24
  • 7
  • 7
1 Solution
 
existenz2Commented:
No this is not really possible in a normal way. The fastest solution is to use frames for the page. It is not very common with ASP.NET, but it does the trick ;)
0
 
mousemat24Author Commented:
damn, the problem is, I cant use frames. Wish there was another way
0
 
existenz2Commented:
The actual problem is caused by the client side javascript. This is stateless by design. However you could make it a bit more statefull by adding a hidden text field in the <form> tags. This textbox should also get posted during a postback. In this textbox you can put which node should be opened in the menu. When the page comes back from the postback you then can read the textbox and set the menu back to the right position.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
mousemat24Author Commented:
existenz2

Can the treeview control in ASP.NET sort this solution out? i.e. it will remember which menu you've clicked on, even if it was a submenu? So when it does postback, it will automatically expand the tree/submenu to the correct menu you've clicked on, and hightlight it as well?

If it can do that, do you think you can send me a link? I've search high and low for an example of this, but the ones I've seen are done in a frameset.

Thanks for replying to me.
0
 
existenz2Commented:
I think the default treeview should solve this problem yes.
0
 
mousemat24Author Commented:
Hi existenz2


Wonder if you can help me with a really quick question. I'm thinking of using VS2005 treeview control, the problem I'm having is when you click on a submenu, the selected item isnt highlighted. Ir collapses the treeview. Can you please help me so that when a user clicks on the link it highlights the item.

Thanks
0
 
existenz2Commented:
0
 
mousemat24Author Commented:
existenz, thanks for that, but that isnt a ASP.NET example
0
 
existenz2Commented:
Oops, that indeed wont work. How about this one: https://secure.codeproject.com/aspnet/ClientSideTreeView.asp
0
 
mousemat24Author Commented:
existenz2

have you used a treeview with menu/submenu, when clicked it refreshes the page, remembering what you clicked on?

It just that I have the most basic example:

<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
   <asp:TreeNode Text="Book Categories" Value="Book Categories">
      <asp:TreeNode Text="Web Development" Value="Web Development">
      <asp:TreeNode Text="ASP.NET" Value="ASP.NET"
                    NavigateUrl="index.aspx?unid={534EF1FF-5776-41BE-83E2-53576A771D58}"></asp:TreeNode>
      <asp:TreeNode Text="Web Services" Value="Web Services"></asp:TreeNode>
      <asp:TreeNode Text="JSP" Value="JSP"></asp:TreeNode>
   </asp:TreeNode>
   <asp:TreeNode Text="Windows Development"
                 Value="Windows Development">
      <asp:TreeNode Text="Windows Forms" Value="Windows Forms"></asp:TreeNode>
      <asp:TreeNode Text="ActiveX Controls" Value="ActiveX Controls"></asp:TreeNode>
      <asp:TreeNode Text="Smart Client" Value="Smart Client"></asp:TreeNode>
      </asp:TreeNode>
   <asp:TreeNode Text="Component Development"
                 Value="Component Development">
      <asp:TreeNode Text="COM" Value="COM"></asp:TreeNode>
      <asp:TreeNode Text="DCOM" Value="DCOM"></asp:TreeNode>
      <asp:TreeNode Text="Remoting" Value="Remoting"></asp:TreeNode>
      </asp:TreeNode>
   </asp:TreeNode>
</Nodes>
    <SelectedNodeStyle BackColor="Red" />
</asp:TreeView>


and when you click on  ASP.NET (index.aspx?unid={534EF1FF-5776-41BE-83E2-53576A771D58}">) it brings the page up, but it dosnt highlight the menu option, whereas it remembers the state if it isnt a link.?
0
 
mousemat24Author Commented:
Hi existenz2

I've sorted it out, but I think I'm doing something wrong, do you think you can have a look at my code?

I'm using the vlaue as the URL, that way I noticed it does a postback, and highlights the selected node. If I place the URL in the NavigateURL, it dosnt do a postback, it refreshs the whole page, this the selected item is gone. And I dont really want to use the "TreeView1.SelectedNode.Value" as it messes the sitemap (it displays the URL). Can you please tell me how I can get it to work with the NavigateURL.

Thanks

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
        string unid = TreeView1.SelectedNode.Value;

        WS_Handbook.Handbook_WS getHTML = new WS_Handbook.Handbook_WS();
        DataSet ds = new DataSet();
        ds = getHTML.displayPage(unid);
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            content.InnerHtml = dr["Content_Body"].ToString();
        }
}
0
 
existenz2Commented:
I can have a look at it, but I dont understand the problem from the code you have pasted. Could you give some more details?
0
 
mousemat24Author Commented:
existenz2

It isnt really a problem, but I dont think I should be adding the URL to the value, I personally think the URL should be in the NavigateURL. So when I hover over one of the nodes, I get the following in the IE status bar.

javascript:__doPostBack('ctl00$TreeView1','sBook Categories\\Web Development\\{534EF1FF-5776-41BE-83E2-53576A771D58}')

the {534EF1FF-5776-41BE-83E2-53576A771D58} is passed to a WEB service, this in turn executes a query in SQL and pulls back data. What I dont like is the string is:

Categories\\Web Development\\{534EF1FF-5776-41BE-83E2-53576A771D58}

I would prefer to have

Categories\\Web Development\\ASP.NET

and when a user clicks on it, it gets the content for {534EF1FF-5776-41BE-83E2-53576A771D58}

And also, having "Categories\\Web Development\\{534EF1FF-5776-41BE-83E2-53576A771D58}" dont look good for sitemaps. Looks much better if it was:

Categories > Web Development >ASP.NET

Hope that makes sense?

Thanks existenz2
0
 
existenz2Commented:
I don't really think that is possible to do so. The sitemap requires something unique and that's why the unique identifier has been chosen and not the url. You might can do the trick with modifing the javascript, but I think that'll cost too much time in comparsion to the benefits.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now