Asp.net 4 TreeView SelectedNodeStyle ImageUrl seems to be ignored - asp.net

I have the following code and no matter what I try to do, it seems the ImageUrl on the SelectedNodeStyle is ignored. Am I doing something backwards?
Note that this thread is a continuation of ASP.Net TreeView with SiteMap is ignoring Node.Selected which asked a different question and revealed this new question.
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
<NodeStyle ForeColor="White" Font-Bold="true" NodeSpacing="5"
HorizontalPadding="5" ImageUrl="~/Images/Page.png" />
<SelectedNodeStyle Font-Bold="true" NodeSpacing="5"
HorizontalPadding="5" ImageUrl="~/Images/Page_Hot.png"/>
<HoverNodeStyle ForeColor="Navy" />
</asp:TreeView>
In the sample above, the selected node underlining works just perfectly. However, the image never changes. Yes, I double-checked the image was named correctly. It changes the other style attributes, just not the image. Quite frustrating.
Solution?

This seems to be a bug and goes back a few years (~2005, 2006). (Excuse the link-filled answer)
http://forums.asp.net/t/943367.aspx
http://connect.microsoft.com/VisualStudio/feedback/details/104297/treeview-selectednodestyle-imageurl-not-working
I would set it in code-behind instead.

Related

Accordion's First Pane Flashes On Partial Postback

I'm using an ASP.NET Accordion control with lots of panes for a data entry form. Within several of the panes are some UpdatePanels, so that some controls within those panels can be enabled or disabled to prevent users from entering values into fields which are precluded by values they've entered elsewhere.
It all works fine, but for some reason, on about half of the occasions where an UpdatePanel postback is triggered (by a specified AsyncPostBack Trigger), the first pane of the Accordion momentarily expands and collapses. This gives that horrible 'flashing' experience you get when a page does a full postback, which is exactly what I'm trying to avoid by using UpdatePanels.
The problem doesn't seem to relate to the contents of the first pane - I tried completely deleting the first pane, so that the second pane became the first, and the same thing happens.
Anybody got any ideas why this is happening and how to fix it?
UPDATED WITH CODE
This is an example of one of the panels. Don't be too offended by the use of a table - it's an actual table, I'm not just using it for layout purposes!
<tr class="grouprow">
<td>Transportation</td>
<td><asp:RadioButtonList ID="rblTransportation" runat="server" RepeatDirection="Horizontal" SelectedValue='<%# Bind("AdmissionTransportation")%>' AutoPostBack="true"
OnSelectedIndexChanged="rblTransportation_SelectedIndexChanged" >
<asp:ListItem Text="Unknown" Value="" />
<asp:ListItem Text="Yes" Value="True" />
<asp:ListItem Text="No" Value="False" />
</asp:RadioButtonList></td><td></td>
</tr>
<tr class="grouprow">
<td>Transportation Duration</td>
<td><asp:UpdatePanel ID="updTransportationHours" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rblTransportation" EventName="selectedindexchanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtTransportationHours" runat="server" Text='<%# Bind("AdmissionTransportationHours")%>' CssClass="tinytextbox" />
<label class="unit">Hours</label>
<asp:RegularExpressionValidator ID="revTransportationHours" runat="server" ControlToValidate="txtTransportationHours" ValidationExpression="\d{1,3}(\.\d{1,2})?"
ValidationGroup="Past30Days" ErrorMessage="Invalid format for Transporation Duration. Please enter in format 'xxx.xx', e.g. '3.25'" Display="Dynamic"
CssClass="error" >*</asp:RegularExpressionValidator>
<asp:RangeValidator ID="rvTransportationDuration" runat="server" ControlToValidate="txtTransportationHours" CssClass="error" ValidationGroup="Past30Days" type="Double"
ErrorMessage="The Transportation Duration cannot be more than 100" MinimumValue="0" MaximumValue="100" >*</asp:RangeValidator>
</ContentTemplate>
</asp:UpdatePanel></td><td></td>
</tr>
I believe you need your rblTransportation RadioButtonList wrapped in an UpdatePanel as well.
Since that control isn't in an UpdatePanel, it causes a full postback.
The answer is gloriously simple, though I'm too tired to figure out why it works just now. I simply need to set ClientIDMode = AutoID on the RadioButtonLists and CheckBoxLists and they now trigger an asynchronous postback rather than a full one. They don't need to be within their own UpdatePanels either.
I got the answer from this SO question.
Can you try <asp:blablacontrol style="Display:none;"> </asp:control>
modalpanels has same problem and this codes solved my problem

Updating Database with value from datepicker control ASP.NET VB

Apologies in advance, for what may be a newbie question. (new to asp.net, coding in VB, zero knowledge of best controls). Please respect that I am not interested in AJAX controls, or using MVC and trying to minimise javascript. What I need to do is very simple in terms of technology.
I am developing a form that allows users to Edit database data. I have chosen to use FormView so that I can format it like a legacy vba app. I am able to set the data source to my database table and the values from the database successfully show up if I allow VWD to automatically format the control. I can edit everything in the database using this form as well.
However, the boss hates having to type dates.
I haven't been able to find a datepicker control with a datasource feature that works like the text boxes that are automatically built in formview (with a bind to a datasource feature). So, I am assuming none exist. I need some assurances that what I think I need to do is the right way.
Instead of using the FormView control's datasource via the front-end automagical stuff, I should instead
place one of these datapicker controls that simply combine calendar with a text box for all date fields in the formview (no disrespect to those who built them, just can't believe they are not more feature-rich, this seems so needed giving the number of datepickers available)
declare my data source in Page_Load and load all the controls if they have existing data utilising FindControl
use Data_Bound block to retrieve the selected values from each control utilising FindControl and build a dynamic SQL string for Update
declare and update my database using one of the code behind blocks, perhaps in the DataBound
Am I on the right track? I have no experience to be confident in my assumption.
and please, if there is an easier way, I'll take it, but I have to make it "pretty".
And suggestions for controls of any sort are welcomed.
---Further into my issue
Here is some code to prove I've actually tried to resolve this...
In my FormView code block I have:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="MASTERID_Action"
DataSourceID="srcAction">
<EditItemTemplate>
MASTERID_Action:
<asp:Label ID="MASTERID_ActionLabel1" runat="server"
Text='<%# Eval("MASTERID_Action") %>' />
<br />
Action_Description:
<asp:TextBox ID="Action_DescriptionTextBox" runat="server"
Text='<%# Bind("Action_Description") %>' />
<br />
Action_Target:
<asp:TextBox ID="Action_TargetTextBox" runat="server"
Text='<%# Bind("Action_Target") %>' />
<br />
Action_Captured:
<asp:TextBox ID="Action_CapturedTextBox" runat="server"
Text='<%# Bind("Action_Captured") %>' />
<br />
Action_Declined:
<asp:TextBox ID="Action_DeclinedTextBox" runat="server"
Text='<%# Bind("Action_Declined") %>' />
<br />
Action_AgreedDate:
<ewc:CalendarPopup ID="CalendarPopup1" runat="server" Culture="en-AU"
PostedDate="" SelectedDate='<%# Bind("Action_AgreedDate") %>'
SelectedValue="01/14/2013 08:47:54" UpperBoundDate="12/31/9999 23:59:59"
VisibleDate="01/14/2013 08:47:54" />
<br />
...
</EditItemTemplate>
My database holds this Action_AgreedDate as nullable.
When I view the ItemTemplate (in the browser) the date shows up as 0.000 (because its a text field and bound to Action_AgreedDate, no error occurs) and when I click Edit to go to the EditItemTemplate I get this error:
Conversion from type 'DBNull' to type 'Date' is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Date' is not valid.
Source Error:
Line 95:
Line 96: Action_AgreedDate:
Line 97: '
Line 99: SelectedValue="01/14/2013 08:47:54" UpperBoundDate="12/31/9999 23:59:59"
I can easily translate this into "the control found a null field and doesn't know what to do with it"; problem is, I don't know what to do. I have checked the properties of the field (the CalendarPOP field to see if there is a setting for handling nulls and nothing is obvious to me. I'm currently trying to find further documentation on the control online. (I've contacted eWorld and hope they will be able to respond.)
I should also add that if I request a record that already has an Action_AgreedDate I get no errors because there is a value present in the database for the control to display.
I think the best way for you to do this would be to use jQuery and jQuery UI, which has a date picker, which can be attached to a regular ASP.NET TextBox in your FormView. So if you had FormView code that looks something like this for example:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource1">
<EditItemTemplate>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%# Eval("solution_id") %>' />
<br />
date_modified:
<asp:TextBox ID="date_modifiedTextBox" runat="server" Text='<%# Bind("date_modified") %>' />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("solution_id") %>' />
<br />
date_modified:
<asp:Label ID="date_modifiedLabel" runat="server" Text='<%# Bind("date_modified") %>' />
</ItemTemplate>
</asp:FormView>
You could run something like this using jQuery UI to get a datepicker on the date_modified text box:
$('[id$=date_modifiedTextBox]').datepicker()
The $('[id$=date_modifiedTextBox]') part is necessary to select the ASP.NET control using jQuery, if it were just a normal element you could just use $('.className') or $('#id') or something like that. Hope this helps.
Problem solved.
I ran across an article on 4GuysFromRolla.com about the RJS POP Calendar (http://preview.tinyurl.com/cerm9xv) and it ticked all the boxes. Successfully implemented it and, because the calendar is separate from the specified text box, it doesn't have to be bound ! It works very nicely. The 4GuysFromRolla save my bacon yet again...

ASP.Net gridview always enters edit mode after an upgrade from platform 3.5 to 4

I have a long-term project (approx 9 years of continual use so far) that uses gridviews in several pages. The gridviews are used to display abbreviated summary details only, each with separate editing forms (hidden until called) being used.
I'm not using in-grid editing as the editing is too complex. The editing form is called and revealed either by the separate Add button or by a row's Edit linkbutton (using a ButtonField).
This approach has worked perfectly for several years upto and including .net 3.5. However, after a recent attempt to upgrade the project platform to .net 4 I found the grids entered in-line edit mode when:
The gridview Edit link button is clicked, and then
The edit form is dismissed by either the cancel button or save button methods
The gridview does not enter the editmode until after the actual editing form is dismissed. If the Save method is invoked, then a full re-bind of the gridview is involved, but it still enters editmode!
I have tried setting the grid's EditIndex to -1, but this doesn't make any difference.
If I reset the compilation target to 3.5 the grids all behave as expected again. I don't have this problem with projects originally started as .net 4 projects.
Partial UI code:
<asp:Button ID="cmdAdd" runat="server" Text=" Add " />
<asp:GridView ID="gvWPHA" runat="server" AutoGenerateColumns="false"
DataKeyNames="PORLID" AllowSorting="false"
EmptyDataText="No records yet" EmptyDataRowStyle-CssClass="qansYes">
<HeaderStyle CssClass="gvhead" />
<RowStyle CssClass="TRPrime" />
<AlternatingRowStyle CssClass="TRAlt" />
<SelectedRowStyle CssClass="TRSelect" />
<Columns>
<asp:ButtonField ButtonType="Link" Text="Edit" CommandName="Edit" />
<asp:BoundField DataField="PORLID" HeaderText="Record #" />
<asp:BoundField DataField="DateOfAppt" SortExpression="DateOfAppt" HeaderText="Appt Date" DataFormatString="{0:dd/MM/yyyy}" />
<asp:BoundField DataField="OutcomeDesc" HeaderText="Outcome" />
<asp:ButtonField ButtonType="Link" Text="Delete" CommandName="Delete" />
</Columns>
</asp:GridView>
<asp:UpdatePanel ID="upEdit" runat="server">
<ContentTemplate>
... Editing Form markup and validation, cancel button, save button, etc ...
</ContentTemplate>
</asp:UpdatePanel>
Has anyone else experienced this problem?
There was a change in the GridView's behavior in .NET 4.0. The Microsoft Connect bug report is here:
https://connect.microsoft.com/VisualStudio/feedback/details/554166/gridview-sets-editindex-property-when-in-previous-net-versions-it-didnt

What is wrong with my Hyperlink

<asp:HyperLink ID="TestHyperLink" runat="server" NavigateUrl='<%# "javascript:updateApplet();" %>' Text="Send" />
It says "The server tag is not well formatted."
Please help.
Missing ID Before "TestHyperLink"
<asp:HyperLink ID="TestHyperLink" runat="server" NavigateUrl='<%# "javascript:updateApplet();" %>' Text="Send" />
There are so many wrong things, have you ever, at least, bother to look in Google ?
<asp:HyperLink
id="TestHyperLink"
runat="server"
NavigateUrl="#"
OnClientClick="updateApplet()"
Text="Send" />
but for simple things like this, you don't need an ASP.NET Control, unless you are doing something from your code file... a simple <a> will do the trick.
Just understand that ASP.NET Controls are useful when we want to tweak or use then in our application as variables so we can control them dynamically. If we simply need a link that will never change, there is no need for a control, a html tag will do.

ASP:MENU I need to show submenu items only on click

I have an asp:menu and I have for eg 3 menuItem: First Second Third and the second item have 2 submenuItems i want to show the 2 submenuitems only when I click on the Second menuitem not when I hover the mouse over. I'll put the code of menu here
<asp:Menu ID="Menu_WebSite" runat="server"
DynamicHorizontalOffset="10" TabIndex="1"
Font-Names="Verdana" Font-Size="12px"
StaticSubMenuIndent="10px" Orientation="Horizontal"
StaticEnableDefaultPopOutImage="false" BackColor="#f0f0f0">
<StaticSelectedStyle ForeColor="Black" />
<DynamicHoverStyle BackColor="#f0f0f0" ForeColor="Black" />
<DynamicMenuItemStyle BackColor="#f0f0f0" HorizontalPadding="25px" VerticalPadding="3px" />
<DynamicMenuStyle BackColor="#f0f0f0" ForeColor="Black" />
<DynamicSelectedStyle BackColor="#f0f0f0" Forecolor="Black" />
<StaticHoverStyle BackColor="#f0f0f0" ForeColor="Black" />
<StaticMenuItemStyle BackColor="#f0f0f0" HorizontalPadding="10px" VerticalPadding="3px" />
<StaticItemTemplate>
<%#Eval("text")%>
</StaticItemTemplate>
</asp:Menu>
my answer is purely theoretical, so you may wish to hold out for someone willing to do leg work for you.
The hover styles can be controlled with CSS. It may be possible to write CSS to ensure the submenu items are hidden even when the user hovers over the main menu items, then change the CSS class dynamically with JavaScript when the user clicks the menu item.
Bearing in mind that clicking the menu item may cause a postback, you may need to show/hide the submenus in server code...
Also, you'll need to consider that you may need to hide the sub menus manually using the onClick event again.
Finally, you may wish to consider not using the ASP Menu for this, because it's designed to be used as a hover menu. You might be better off writing your own implementation, depending on whether you really need the ASP Menu functionality. There are many examples of good menus online, so you might find one that does what you're looking for with more ease. The ASP.NET TreeView control may provide you with a much closer starting point.
A quick Google throws up the following blog that may be what you're looking for:
http://msd-bml.blogspot.com/2008/09/aspnet-menu-click-instead-of-hover.html

Resources