Solved

Stop post back for certain <div>'s

Posted on 2006-11-01
14
186 Views
Last Modified: 2012-08-13
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
Comment
Question by:mousemat24
  • 7
  • 7
14 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 17848537
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
 

Author Comment

by:mousemat24
ID: 17848791
damn, the problem is, I cant use frames. Wish there was another way
0
 
LVL 14

Expert Comment

by:existenz2
ID: 17848844
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
 

Author Comment

by:mousemat24
ID: 17849021
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
 
LVL 14

Expert Comment

by:existenz2
ID: 17849102
I think the default treeview should solve this problem yes.
0
 

Author Comment

by:mousemat24
ID: 17849470
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
 
LVL 14

Expert Comment

by:existenz2
ID: 17849621
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:mousemat24
ID: 17849687
existenz, thanks for that, but that isnt a ASP.NET example
0
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 17849837
Oops, that indeed wont work. How about this one: https://secure.codeproject.com/aspnet/ClientSideTreeView.asp
0
 

Author Comment

by:mousemat24
ID: 17850418
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
 

Author Comment

by:mousemat24
ID: 17856770
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
 
LVL 14

Expert Comment

by:existenz2
ID: 17856875
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
 

Author Comment

by:mousemat24
ID: 17857266
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
 
LVL 14

Expert Comment

by:existenz2
ID: 17864880
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 run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now