How to highlight a selected item in RadMenu? - radmenu

I have a RadMenu and I wish the selected item to be highlighted when clicked. But I am unable to get the desired result...
Below is my code in ascx.cs file:
namespace HGS.HGSAdmin.UserControl
{
public partial class UCLeftMenu : System.Web.UI.UserControl
{
protected void Page_Load(object sender, GridItemEventArgs e)
{
RadMenuItem item = RadLeftMenu.FindItemByUrl(Request.Url.PathAndQuery);
if (item != null)
{
Response.Write(item.Text);
foreach (RadMenuItem childItem in item.Menu.GetAllItems())
{
childItem.CssClass = "";
}
item.CssClass = "focused";
while (item.Owner is RadMenuItem)
{
((RadMenuItem)item.Owner).CssClass = "focused";
item = (RadMenuItem)item.Owner;
}
}
}
protected void RadLeftMenu_ItemClick(object sender, RadMenuEventArgs e)
{
foreach (RadMenuItem childItem in e.Item.Menu.GetAllItems())
{
childItem.CssClass = "";
}
e.Item.CssClass = "focused";
RadMenuItem item = e.Item;
while (item.Owner is RadMenuItem)
{
((RadMenuItem)item.Owner).CssClass = "focused";
item = (RadMenuItem)item.Owner;
}
}
}
}
And below is my ascx page:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="UCLeftMenu.ascx.cs"
Inherits="HGS.HGSAdmin.UserControl.UCLeftMenu" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<script src="../../Script/RadMenu.js" type="text/javascript"></script>
<link href="../../Styles/styles_RadMenu.css" rel="stylesheet" type="text/css" />
<table valign="top">
<tr>
<td rowspan="2" class="contarea">
</td>
</tr>
<tr>
<td width="192" align="left" valign="top" class="menumid">
<telerik:RadScriptManager ID="ScriptManager" runat="server">
</telerik:RadScriptManager>
<telerik:RadMenu ID="RadLeftMenu" runat="server" EnableEmbeddedSkins="true" EnableRoundedCorners="true"
Flow="Vertical" EnableShadows="true" OnItemClick="RadLeftMenu_ItemClick">
<%--<LoadingStatusTemplate>
<asp:Image runat="server" ID="LoadingImage" ImageUrl="Images/loading.gif" ToolTip="Loading..." Width="16px" Height="16px" style="margin-top:8px" />
</LoadingStatusTemplate>--%>
<Items>
<telerik:RadMenuItem runat="server" Text=". Home" NavigateUrl="../FrmStaticPage.aspx?h">
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". About Us" NavigateUrl="../FrmStaticPage.aspx?a">
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". Services" NavigateUrl="../FrmStaticPage.aspx?s">
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". Gallery" NavigateUrl="../FrmStaticPage.aspx?g">
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". Contact Us" NavigateUrl="../FrmStaticPage.aspx?c">
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". Testimonials" NavigateUrl="../FrmTestimonials.aspx?t">
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". Links" NavigateUrl="../FrmStaticPage.aspx?l">
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". Featured Services" NavigateUrl="~/HGSAdmin/FrmFeaturedServices.aspx">
<GroupSettings Flow="Vertical" />
</telerik:RadMenuItem>
<telerik:RadMenuItem runat="server" Text=". Banner Images" NavigateUrl="../Banner.aspx">
</telerik:RadMenuItem>
</Items>
</telerik:RadMenu>
</td>
</table>
Can anyone please guide? Many thanks!

You can easily achieve this by the HighlightPath() function of the RadMenu. Take a look at this Telerik demo for an example.

Related

My asp.net code is not detecting the textboxes in LoginView control

Firstly, I am new to asp.net so please be patient with me. I have
created a Login control in the .aspx page. I am trying to access the
username textbox called 'UserName' and the password textbox called
'Password', but when I build the application, I get the following errors:
Login does not contain a definition for 'Username'
Login does not contain a definition for 'Password'
The textboxes both have the correct id values, so I cannot understand
why asp.net is not locating the textbox controls. Please help!!
The following code for the Login.aspx page is:
<%# Page Language="C#" MasterPageFile="~/Template.master"
AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login"
Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:Login ID="Login1" runat="server" Width="50%"
OnAuthenticate="Login1_Authenticate" >
<LayoutTemplate>
<table border="1px solid yellow" cellpadding="0" cellspacing="0"
width="50%">
<tr>
<td style="height: 24px"><asp:Label runat="server" ID="lblUserName"
AssociatedControlID="UserName" Text="Email:" /></td>
<td style="height: 24px"><asp:TextBox id="UserName"
runat="server"
Width="55%" /></td>
<td style="height: 24px"></td>
</tr>
<tr>
<td><asp:Label runat="server" ID="lblPassword"
AssociatedControlID="Password" Text="Password:" />
</td>
<td><asp:TextBox ID="Password" runat="server"
TextMode="Password"
Width="95%" /></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="80%"
style="border: solid 1px red";>
<tr>
<td><asp:CheckBox ID="RememberMe" CssClass="chkrememberMe"
runat="server" Text="Remember me" >
</asp:CheckBox>
</td>
<td> </td>
</tr>
</table>
<asp:HyperLink ID="lnkRegister" CssClass="linkButtonReg"
runat="server"
NavigateUrl="~/Register.aspx">Create new account
</asp:HyperLink><br />
<asp:HyperLink ID="lnkPasswordRecovery" CssClass="linkButtonPass"
runat="server" NavigateUrl="~/PasswordRecovery.aspx" >I forgot my
password
</asp:HyperLink>
</div>
</LayoutTemplate>
</asp:Login>
</AnonymousTemplate>
</asp:LoginView>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="RightContent"
Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="LeftContent"
Runat="Server">
</asp:Content>
The code behind file for
The Login.aspx.cs is:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Login : System.Web.UI.Page
{
string userEmail = "";
string userName = "";
string password = "";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender,
AuthenticateEventArgs e)
{
Login Login1 = ((Login)LoginView1.FindControl("Login1"));
userEmail = Login1.UserName.ToString();
userName = Membership.GetUserNameByEmail(userEmail);
password = Login1.Password.ToString();
if (Membership.ValidateUser(userName, password))
{
e.Authenticated = true;
Login1.UserName = userName;
}
else
{
e.Authenticated = false;
}
}
}

Access Detail Table datakeynames on rowdrop event telerik

I am using telerik nested rad grid. Please take a look at code.
<telerik:RadGrid ID="radGridRoutes" runat="server" AutoGenerateColumns="false" ShowStatusBar="True"
AllowSorting="True" AllowPaging="True" ClientSettings-Scrolling-EnableVirtualScrollPaging="false"
ClientSettings-Scrolling-AllowScroll="false"
OnNeedDataSource="Routes_NeedDataSource" OnDetailTableDataBind="radGridRoutes_DetailTableDataBind" AllowFilteringByColumn="True"
EnableLinqExpressions="false" OnInsertCommand="Routes_InsertCommand"
OnUpdateCommand="radGridRoutes_UpdateCommand"
OnItemCommand="radGridRoutes_ItemCommand"
OnPreRender="radGridRoutes_PreRender" ClientSettings-AllowRowsDragDrop="true"
OnRowDrop="radGridRoutes_RowDrop">
<ClientSettings AllowDragToGroup="True">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<GroupingSettings CaseSensitive="false" />
<SelectedItemStyle CssClass="SelectedItem" />
<PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
<ValidationSettings CommandsToValidate="PerformInsert,Update" EnableModelValidation="true"
EnableValidation="true" />
<FilterItemStyle BackColor="#F8F8F8" HorizontalAlign="Left" />
<FilterMenu EnableImageSprites="false">
</FilterMenu>
<MasterTableView DataKeyNames="ID" AllowMultiColumnSorting="false"
Width="100%" CommandItemDisplay="Top" Name="Routes">
<AlternatingItemStyle BackColor="WhiteSmoke" />
<DetailTables>
<telerik:GridTableView OnRowDrop="radGridRoutes_RowDrop" ClientSettings-AllowRowsDragDrop="true"
DataKeyNames="ID,DisplayOrder,RouteID" Width="100%" runat="server"
CommandItemDisplay="Top" Name="Stops" AllowFilteringByColumn="false">
<CommandItemSettings AddNewRecordText="Add New Stops" ShowAddNewRecordButton="true" />
<ParentTableRelation>
<%-- <telerik:GridRelationFields DetailKeyField="ID" MasterKeyField="ID" />--%>
</ParentTableRelation>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditTask" EditText="Edit"
UpdateText="Update" CancelText="Cancel">
<HeaderStyle Width="20px" />
</telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn SortExpression="Name" HeaderText="Name" UniqueName="Name"
HeaderButtonType="TextButton" HeaderStyle-Width="15%" ItemStyle-Width="15%" DataField="tName">
<ItemTemplate>
<%# Eval("Name")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Width="250px" Text='<%# Eval("Name")%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredName" ControlToValidate="txtName"
CssClass="validationMessage" ErrorMessage="Name is required."
Text="* required" runat="server" Display="Dynamic"></asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="Comment" HeaderText="Comment" UniqueName="Comment"
HeaderButtonType="TextButton" DataField="Comment">
<ItemTemplate>
<%# Eval("Comment")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtComment" TextMode="MultiLine" Rows="4" Width="250px" runat="server" Text='<%# Eval("Comment")%>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="Address" HeaderText="Address"
DataField="Address" UniqueName="Address" HeaderButtonType="TextButton">
<ItemTemplate>
<%# Eval("Address")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAddress" Width="250px" TextMode="MultiLine" Text='<%# Bind("Address") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="Phone" HeaderText="Phone" UniqueName="Phone"
HeaderButtonType="TextButton" DataField="Phone">
<ItemTemplate>
<%# Eval("Phone")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPhone" Rows="4" Width="250px" runat="server" Text='<%# Eval("Phone")%>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="Email" HeaderText="Email" UniqueName="Email"
HeaderButtonType="TextButton" DataField="Email">
<ItemTemplate>
<%# Eval("Email")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEmail" Rows="4" Width="250px" runat="server" Text='<%# Eval("Email")%>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="ManagerName" HeaderText="ManagerName" UniqueName="ManagerName"
HeaderButtonType="TextButton" DataField="ManagerName">
<ItemTemplate>
<%# Eval("ManagerName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtManagerName" Rows="4" Width="250px" runat="server" Text='<%# Eval("ManagerName")%>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="NumberOfRooms" HeaderText="#Rooms" UniqueName="NumberOfRooms"
HeaderButtonType="TextButton" DataField="NumberOfRooms">
<ItemTemplate>
<%# Eval("NumberOfRooms")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtNumberOfRooms" Width="250px" Rows="4" runat="server" Text='<%# Eval("NumberOfRooms")%>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="Merchandising" HeaderText="Merchandising" UniqueName="Merchandising"
HeaderButtonType="TextButton" DataField="Merchandising">
<ItemTemplate>
<%# Eval("Merchandising")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtMerchandising" Width="250px" Rows="4" runat="server" Text='<%# Eval("Merchandising")%>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="Frequency" HeaderText="Frequency"
DataField="Frequency" UniqueName="Frequency" HeaderButtonType="TextButton">
<ItemTemplate>
<%# GetFrequencyName(Convert.ToInt32(Eval("FrequencyID"))) %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="drpFreq" runat="server" DataTextField="Name" DataValueField="ID"
AppendDataBoundItems="true">
<asp:ListItem Text="--Select--" Value="-1">
</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="DisplayOrder" HeaderText="Display Order" UniqueName="DisplayOrder"
HeaderButtonType="TextButton" HeaderStyle-Width="15%" ItemStyle-Width="15%" DataField="DisplayOrder">
<ItemTemplate>
<%# Eval("DisplayOrder")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDisplayOrder" runat="server" Width="250px" Text='<%# Eval("DisplayOrder")%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredDisplayOrder" ControlToValidate="txtDisplayOrder"
CssClass="validationMessage" ErrorMessage="Display Order is required."
Text="* required" runat="server" Display="Dynamic"></asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Delete" AllowFiltering="false">
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" CommandName="DeleteStops" CommandArgument=' <%# Eval("ID") %>' runat="server" OnClientClick="javascript:if (!confirm('Are you sure you want to delete Stop?')) {
return false;
}">Delete</asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</telerik:GridTableView>
</DetailTables>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" CancelText="Cancel" EditText="Edit"
UpdateText="Update" UniqueName="EditRoutes" ItemStyle-Width="5%">
<HeaderStyle Width="5%" />
</telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn SortExpression="Name" HeaderText="Name" UniqueName="RouteName"
HeaderButtonType="TextButton" HeaderStyle-Width="20%" ItemStyle-Width="20%" DataField="Name">
<ItemTemplate>
<%# Eval("Name")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtRouteName" runat="server" Text='<%# Eval("Name")%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="requiredRouteName" ControlToValidate="txtRouteName"
CssClass="validationMessage" ErrorMessage="Name is required."
Text="* required" runat="server" Display="Dynamic"></asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn SortExpression="Comment" HeaderText="Comment" UniqueName="Comment"
HeaderButtonType="TextButton" DataField="Comment">
<ItemTemplate>
<%# Eval("Comment")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtComment" TextMode="MultiLine" Rows="4" Width="250px" runat="server" Text='<%# Eval("Comment")%>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Delete" AllowFiltering="false">
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" CommandName="Delete" CommandArgument=' <%# Eval("ID") %>' runat="server" OnClientClick="javascript:if (!confirm('Are you sure you want to delete route?')) {
return false;
}">Delete</asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<SortExpressions>
<telerik:GridSortExpression FieldName="Name"></telerik:GridSortExpression>
</SortExpressions>
<CommandItemSettings AddNewRecordText="Add New Route" ShowAddNewRecordButton="true" />
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
And the code behind rowDrop event is
protected void radGridRoutes_RowDrop(object sender, GridDragDropEventArgs e)
{
GridDataItem RowDragged = e.DraggedItems.FirstOrDefault();
e.DraggedItems[0].GetDataKeyValue("DisplayOrder");
int OriginalID = Convert.ToInt32(RowDragged.GetDataKeyValue("ID"));
int OriginalOrder = Convert.ToInt32(RowDragged.GetDataKeyValue("DisplayOrder"));
int RouteID = Convert.ToInt32(RowDragged.GetDataKeyValue("RouteID"));
int DestID = Convert.ToInt32(e.DestDataItem.GetDataKeyValue("ID"));
int DestOrder = Convert.ToInt32(e.DestDataItem.GetDataKeyValue("DisplayOrder"));
UpdateOrder(OriginalID, OriginalOrder, DestID, RouteID);
}
Now the problem is i want to access the datakeyNames from the nested gridTableView. I am not able to figure that out. Please provide me suggestions how to get the ID,DisplayOrder,RouteID from nested gridtableview in rowdrop event. Currently it is giving null values to me.
Please try with the below code snippet.
ASPX
<telerik:GridTableView Name="Child" OnRowDrop="radGridRoutes_RowDrop" ClientSettings-AllowRowsDragDrop="true" DataKeyNames="ID,DisplayOrder,RouteID" Width="100%" runat="server" CommandItemDisplay="Top" Name="Stops" AllowFilteringByColumn="false">
ASPX.CS
protected void radGridRoutes_RowDrop(object sender, GridDragDropEventArgs e)
{
GridDataItem RowDragged = e.DraggedItems.FirstOrDefault();
if (RowDragged.OwnerTableView.Name == "Child")
{
// Row Dragged from child Grid
e.DraggedItems[0].GetDataKeyValue("DisplayOrder");
int OriginalID = Convert.ToInt32(RowDragged.GetDataKeyValue("ID"));
int OriginalOrder = Convert.ToInt32(RowDragged.GetDataKeyValue("DisplayOrder"));
int RouteID = Convert.ToInt32(RowDragged.GetDataKeyValue("RouteID"));
// You can also check same thing for Drop Item
int DestID = Convert.ToInt32(e.DestDataItem.GetDataKeyValue("ID")); int DestOrder = Convert.ToInt32(e.DestDataItem.GetDataKeyValue("DisplayOrder"));
UpdateOrder(OriginalID, OriginalOrder, DestID, RouteID);
}
}
Update 1:
If above code is not working then please try with the below code snippet.
Method 1:
ASPX
<telerik:GridTableView Name="Child" ClientDataKeyNames="ID,DisplayOrder,RouteID" OnRowDrop="radGridRoutes_RowDrop" ClientSettings-AllowRowsDragDrop="true" DataKeyNames="ID,DisplayOrder,RouteID" Width="100%" runat="server" CommandItemDisplay="Top" Name="Stops" AllowFilteringByColumn="false">
......
......
<ClientSettings>
<ClientEvents OnRowDragStarted="RowDragStarted" />
</ClientSettings>
JS Code
function RowDragStarted(sender, eventArgs) {
var tblvew = eventArgs.get_tableView().get_name();
if(tblvew == null || tblvew == undefined || tblvew != 'Child')
{
eventArgs.set_cancel(true);
}
}
OR
function RowDragStarted(sender, eventArgs) {
var route = eventArgs.getDataKeyValue("RouteID");
if(route == null || route == '')
{
eventArgs.set_cancel(true);
}
}
Let me know if any concern.

ModalPopupExtender in UserControl

I want to have a UserControl which represents an input dialog (panel with customizable labels and textboxes). This UserControl needs to be opened via a ModalPopupExtender.
I started with the following solution which works, but is not in a UC:
<!-- Popup to add brand -->
<asp:Panel ID="pnlAddPopup" DefaultButton="cmdOk" runat="server" style="display: none;">
<atk:ModalPopupExtender ID="popupExtender" runat="server" TargetControlID="cmdAdd" PopupControlID="pnlAddPopup" CancelControlID="cmdAbbrechen" BackgroundCssClass="modalBackground" />
<div id="Div1" style="border-style: none; padding: 5px;" runat="server">
<table style="border: 0">
<tr>
<td style="background-color: #CCCCCC; height: 15px; text-align: right" />
</tr>
<tr>
<td style="background-color: #FFE580;">
<div style="padding: 10px;">
<cc1:SDDataLabel ID="name" runat="server" Text="Name"/>
<cc1:SDTextBox ID="txtInput" Width="300" runat="server"/>
</div>
</td>
</tr>
<tr>
<td style="background-color: #FFE580; height: 20px; text-align: center">
<cc1:SDButton ID="cmdOk" OnClick="CmdAddOkClick" CssClass="button" runat="server" />
<cc1:SDButton ID="cmdAbbrechen" CssClass="button" runat="server" />
</td>
</tr>
</table>
</div>
</asp:Panel>
What I would prefer: If I could add one single line like
<uc1:InputPopup ID="inputPopup" runat="server" TargetControlID="cmdAdd"/>
So I created the following "InputPopup" UserControl:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="InputPopup.ascx.cs" Inherits="ABC.InputPopup" %>
<%# Register Assembly="ABC" TagPrefix="cc1" Namespace="ABC" %>
<atk:ModalPopupExtender ID="popupExtender" runat="server" PopupControlID="pnlAddPopup" CancelControlID="cmdAbbrechen" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlAddPopup" DefaultButton="cmdOk" runat="server" style="display: none;">
<div id="Div1" style="border-style: none; padding: 5px;" runat="server">
<table style="border: 0">
<tr>
<td style="background-color: #CCCCCC; height: 15px; text-align: right" />
</tr>
<tr>
<td style="background-color: #FFE580;">
<div style="padding: 10px;">
<cc1:SDDataLabel ID="name" runat="server" Text="Name"/>
<cc1:SDTextBox ID="txtInput" Width="300" runat="server"/>
</div>
</td>
</tr>
<tr>
<td style="background-color: #FFE580; height: 20px; text-align: center">
<cc1:SDButton ID="cmdOk" OnClick="CmdAddOkClick" CssClass="button" runat="server" />
<cc1:SDButton ID="cmdAbbrechen" CssClass="button" runat="server" />
</td>
</tr>
</table>
</div>
</asp:Panel>
In addition, I have the code behind file which does define the property TargetControlID.
public TargetControlID TargetControlID
{
set{ popupExtender.TargetControlID = value;}
}
This solution would be great, but does not work, since the ModalPopupExtender is not listening on the cmdAdd since the cmdAdd is placed in the parent control...
My question: Is it possible to overwrite the TargetControlID setter of ModalPopupExtender in order to listen to the right control click event (the one which is located in the parent control in my case)?
Or is there any other solution for my problem? I read about using
$("#<%= popupExtender.ClientID").show()
as OnClientClick function on the TargetControl, but I am not able to do this in the parent control, since popupExtender would be in the UC.
What also works is the following solution. But I would prefer the "one line UC solution" above, without the ModalPopupExtender in the parent control
<cc1:SDButton ID="cmdAdd" CssClass="button" runat="server" />
<!-- Popup to add brand -->
<atk:ModalPopupExtender ID="popupExtender" runat="server" TargetControlID="cmdAdd" PopupControlID="pnlAddPopup" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlAddPopup" runat="server">
<uc1:InputPopup ID="inputPopup" runat="server"/>
</asp:Panel>
The code of the UserControl with the ModalPopupExtender -> PopupInputPanelOkCancel.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="PopupInputPanelOkCancel.ascx.cs" Inherits="ABC.PopupPanels.PopupInputPanelOkCancel" %>
<%# Register TagPrefix="atk" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit, Version=4.5.7.607, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>
<span style="display:none">
<asp:Button runat="server" ID="dummyButton" />
</span>
<atk:ModalPopupExtender ID="popupExtender" runat="server" PopupControlID="pnlPopup" TargetControlID="dummyButton" CancelControlID="cmdAbbrechen" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" DefaultButton="cmdOk" runat="server">
<div id="Div1" style="border-style: none; padding: 5px;" runat="server">
<table style="border: 0">
<tr>
<td style="background-color: #CCCCCC; height: 15px; text-align: right" />
</tr>
<tr>
<td style="background-color: #FFE580;">
<div style="padding: 10px;">
<asp:Label ID="lblLabel" runat="server" Text="Name"/>
<asp:TextBox ID="txtInput" Width="300" runat="server"/>
</div>
</td>
</tr>
<tr>
<td style="background-color: #FFE580; height: 20px; text-align: center">
<asp:Button ID="cmdOk" OnClick="CmdOkClick" CssClass="button" runat="server" />
<asp:Button ID="cmdAbbrechen" CssClass="button" runat="server" />
</td>
</tr>
</table>
</div>
</asp:Panel>
In the code behind, I have a property to set the BehaviorId of the extender and one to get the field on which we should set the focus after the panel pops up -> PopupInputPanelOkCancel.ascx.cs
public string BehaviorId
{
get { return popupExtender.BehaviorID; }
set { popupExtender.BehaviorID = value; }
}
public string FocusId
{
get { return txtInput.ClientID; }
}
In the aspx page, I add the control like this:
<uc1:PopupInputPanelOkCancel ID="PopupInputPanelOkCancel1" BehaviorId="addPopupBehaviorId" runat="server"/>
Make sure that you add the scriptmanager on top of the page (if not added somewhere else in a parent control.
<asp:ScriptManager ID="asm" runat="server" />
To call the show method, I added the following code to a button:
<asp:Button ID="cmdSorteAdd" CssClass="button" runat="server" OnClientClick="showModalPopupExtender('addPopupBehaviorId');return false;" />
Additionally, I added the following javascript code at the end of the aspx page
<script type="text/javascript">
function pageLoad() {
// $find is not jQuery. It's from MS and returns an AJAX control.
var modal = $find('<%=PopupInputPanelOkCancel1.BehaviorId%>');
if (modal != null) {
modal.add_shown(modalPopupExtenderShown);
}
}
function showModalPopupExtender(modalBehaviorId) {
// $find is not jQuery. It's from MS and returns an AJAX control.
var modal = $find(modalBehaviorId);
if (modal != null) {
modal.show();
}
}
function modalPopupExtenderShown() {
//jQuery selector
$('#<%=PopupInputPanelOkCancel1.FocusId%>').focus();
}
</script
What I don't like yet is that I need to set the value of BehaviorId (addPopupBehaviorId) manually in the
OnClientClick="showModalPopupExtender('addPopupBehaviorId');return false;"
It would be perfect if one would need to add it only in the
<uc1:PopupInputPanelOkCancel ID="PopupInputPanelOkCancel1" BehaviorId="addPopupBehaviorId" runat="server"/>
But it does work :)
My problem I am still on is that when the function modalPopupExtenderShown is called, the focus() does fire a postback in my case. I don't understand why there is a postback. Do you have any ideas? -> Edit: I used the wrong function. I used Microsofts $find('id').focus() instead of jQuery's $('#id').focus() to set the focus. Now, everything works like a charm.
Other than that, my solution works fine and I hope that someone finds it useful.

sharepoint changecontenttype dropdown

SharePoint ChangeContentType DropDown
I have attached an application page to the custom document based content type as its edit form.
That content type is being used in a document library which has more than one content type attached to it.
SharePoint form field controls render the respective fields correctly. Change content type control lists all the content types related to the lists in a dropdown as well. But when I change the selection, means when I select different content type, the form does not show the set of fields for the selected content type rather it stays as it is.
Code:
<%# Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%# Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%# Import Namespace="Microsoft.SharePoint" %>
<%# Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationPage1.aspx.cs" Inherits="DMS_POC.Layouts.DMS_POC.ApplicationPage1" DynamicMasterPageFile="~masterurl/default.master" %>
<%# Register TagPrefix="wssuc" TagName="ToolBar" src="../../../_controltemplates/15/ToolBar.ascx" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table>
<tr>
<td>
<span id='part1'>
<SharePoint:InformationBar ID="InformationBar1" runat="server" />
<div id="listFormToolBarTop">
<wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&#160;" runat="server">
<template_rightbuttons>
<SharePoint:NextPageButton ID="NextPageButton1" runat="server"/>
<SharePoint:SaveButton ID="SaveButton1" runat="server"/>
<SharePoint:GoBackButton ID="GoBackButton1" runat="server"/>
</template_rightbuttons>
</wssuc:ToolBar>
</div>
<SharePoint:ItemValidationFailedMessage ID="ItemValidationFailedMessage1" runat="server" />
<table class="ms-formtable" style="margin-top: 8px;" border="0" cellpadding="0" cellspacing="0" width="100%">
<SharePoint:ChangeContentType ID="ChangeContentType1" runat="server" />
<SharePoint:FolderFormFields ID="FolderFormFields1" runat="server" />
<tr>
<td>
<SharePoint:FieldLabel ID="lbl_ProposalNumber" runat="server" FieldName="ProposalNo" />
</td>
<td>
<SharePoint:FormField ID="field_ProposalNumber" runat="server" FieldName="ProposalNo"
ControlMode="Display" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>
<SharePoint:FieldLabel ID="lbl_CustName" runat="server" FieldName="CustomerName" />
</td>
<td>
<SharePoint:FormField ID="field_CustName" runat="server" FieldName="CustomerName"
ControlMode="Edit" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>
<SharePoint:FieldLabel ID="lbl_ProposalType" runat="server" FieldName="ProposalType" />
</td>
<td>
<SharePoint:FormField ID="field_ProposalType" runat="server" FieldName="ProposalType"
ControlMode="Edit" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>
<SharePoint:FieldLabel ID="lbl_RevertBy" runat="server" FieldName="RevertBy" />
</td>
<td>
<SharePoint:FormField ID="field_RevertBy" runat="server" FieldName="RevertBy"
ControlMode="Edit" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td style="vertical-align:top">
<SharePoint:FieldLabel ID="lbl_Details" runat="server" FieldName="Details" />
</td>
<td style="vertical-align:top">
<SharePoint:FormField ID="field_Details" runat="server" FieldName="Details"
ControlMode="Edit" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>
<SharePoint:FieldLabel ID="lbl_SignRequired" runat="server" FieldName="DigitalSignatureRequired" />
</td>
<td>
<SharePoint:FormField ID="field_SignRequired" runat="server" FieldName="DigitalSignatureRequired"
ControlMode="Edit" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>
<SharePoint:FieldLabel ID="lbl_Amount" runat="server" FieldName="Amount" />
</td>
<td>
<SharePoint:FormField ID="field_Amount" runat="server" FieldName="Amount"
ControlMode="Edit" />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>
<SharePoint:FieldLabel ID="lbl_Final" runat="server" FieldName="Final" />
</td>
<td>
<SharePoint:FormField ID="field_Final" runat="server" FieldName="Final"
ControlMode="Edit" />
</td>
</tr>
<SharePoint:ApprovalStatus ID="ApprovalStatus1" runat="server" />
<SharePoint:FormComponent ID="FormComponent1" TemplateName="AttachmentRows" ComponentRequiresPostback="false" runat="server" />
</table>
<table cellpadding="0" cellspacing="0" width="100%" style="padding-top: 7px">
<tr>
<td width="100%">
<SharePoint:ItemHiddenVersion ID="ItemHiddenVersion1" runat="server" />
<SharePoint:ParentInformationField ID="ParentInformationField1" runat="server" />
<SharePoint:InitContentType ID="InitContentType1" runat="server" />
<wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator="&#160;" runat="server">
<template_buttons>
<SharePoint:CreatedModifiedInfo ID="CreatedModifiedInfo1" runat="server"/>
</template_buttons>
<template_rightbuttons>
<SharePoint:SaveButton ID="SaveButton2" runat="server"/>
<SharePoint:GoBackButton ID="GoBackButton2" runat="server"/>
</template_rightbuttons>
</wssuc:ToolBar>
</td>
</tr>
</table>
</span>
</td>
<td valign="top">
<SharePoint:DelegateControl ID="DelegateControl1" runat="server" ControlId="RelatedItemsPlaceHolder" />
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Application Page
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
My Application Page
</asp:Content>
This is an old question but got here while looking for something else.
In case you never found the solution or someone else ends up here here is what you need to do
Add the following in your aspx:
<tr><SharePoint:ListFieldIterator runat="server" ID="ListFieldIterator1" ControlMode="Edit" ExcludeFields="FileLeafRef"/></tr>
This will allow the ChangeContentType control to refresh the fields based on content types. You also don't need all those hard coded form fields as the purpose of the ListFieldIterator is to render the form with the correct controls for you.
Your next problem will probably be to set the values of each control assuming that is what you want to do. For each control type you have to look at the Controls and look for controls like TextBox or DropDownList, etc. Most of the time the control will be deep inside as in something like ((TextBox)control.Controls[1].Controls[0].Control[2]).Text
Not the most elegant way but this is all I could find to make it work.
If you don't need to map values then the first part of my answer is all you need and should be easy to do.
Good luck!

Getting a user name through java script in sharepoint aspx page

I am using Microsoft Office 365 (Plan P1). I have a user "ABC". I want that whenever ABC logs in, he is redirected to a specific site let's say Marketing site.
I am writing a javascript code as below:
<script type="text/javascript" language="javascript">
if(document.getElementById('<%=LoginName1.ClientID %>') == "ABC";
location.href="/teamsite/Home.aspx";
</script>
But I am getting error that code blocks not allowed. Can someone help?
Below is the code of page:
<%-- _lcid="1033" _version="14.0.4762" _dal="1" --%>
<%-- _LocalBinding --%>
<%# Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" %>
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Import Namespace="Microsoft.SharePoint" %> <%# Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%# Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
<SharePoint:ListItemProperty Property="BaseName" maxlength="40" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
<WebPartPages:WebPartZone runat="server" title="loc:TitleBar" id="TitleBar" AllowLayoutChange="false" AllowPersonalization="false"><ZoneTemplate>
<WebPartPages:TitleBarWebPart runat="server" AllowEdit="True" AllowConnect="True" ConnectionID="00000000-0000-0000-0000-000000000000" Title="Web Part Page Title Bar" IsIncluded="True" Dir="Default" IsVisible="True" AllowMinimize="False" ExportControlledProperties="True" ZoneID="TitleBar" ID="g_771de8f3_6bde_473c_ade0_fd62f3baa052" HeaderTitle="Calculating..." AllowClose="False" FrameState="Normal" ExportMode="All" AllowRemove="False" AllowHide="True" SuppressWebPartChrome="False" DetailLink="" ChromeType="None" HelpLink="" MissingAssembly="Cannot import this Web Part." PartImageSmall="" HelpMode="Modeless" FrameType="None" AllowZoneChange="True" PartOrder="1" Description="" PartImageLarge="" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{771DE8F3-6BDE-473C-ADE0-FD62F3BAA052}" WebPart="true" Height="" Width=""></WebPartPages:TitleBarWebPart>
<WebPartPages:TitleBarWebPart runat="server" AllowEdit="True" AllowConnect="True" ConnectionID="00000000-0000-0000-0000-000000000000" Title="Web Part Page Title Bar" IsIncluded="True" Dir="Default" IsVisible="True" AllowMinimize="False" ExportControlledProperties="True" ZoneID="TitleBar" ID="g_ea882083_ab10_4e70_9986_6cbe1640086a" HeaderTitle="Calculating..." AllowClose="False" FrameState="Normal" ExportMode="All" AllowRemove="False" AllowHide="True" SuppressWebPartChrome="False" DetailLink="" ChromeType="None" HelpLink="" MissingAssembly="Cannot import this Web Part." PartImageSmall="" HelpMode="Modeless" FrameType="None" AllowZoneChange="True" PartOrder="2" Description="" PartImageLarge="" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{EA882083-AB10-4E70-9986-6CBE1640086A}" WebPart="true" Height="" Width=""></WebPartPages:TitleBarWebPart>
</ZoneTemplate></WebPartPages:WebPartZone>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server">
<style type="text/css">
Div.ms-titleareaframe {
height: 100%;
}
.ms-pagetitleareaframe table {
background: none;
}
</style>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<meta name="GENERATOR" content="Microsoft SharePoint" />
<meta name="ProgId" content="SharePoint.WebPartPage.Document" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="CollaborationServer" content="SharePoint Team Web Site" />
<script type="text/javascript">
// <![CDATA[
var navBarHelpOverrideKey = "WSSEndUser";
// ]]>
</script>
<SharePoint:UIVersionedContent ID="WebPartPageHideQLStyles" UIVersion="4" runat="server">
<ContentTemplate>
<style type="text/css">
body #s4-leftpanel {
display:none;
}
.s4-ca {
margin-left:0px;
}
</style>
</ContentTemplate>
</SharePoint:UIVersionedContent>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderSearchArea" runat="server">
<SharePoint:DelegateControl runat="server"
ControlId="SmallSearchInputBox"/>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderLeftActions" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderPageDescription" runat="server">
<SharePoint:ProjectProperty Property="Description" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderBodyRightMargin" runat="server">
<div height="100%" class="ms-pagemargin"><img src="/_layouts/images/blank.gif" width="10" height="1" alt="" /></div>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr>
<td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" width="100%">
<WebPartPages:WebPartZone runat="server" Title="loc:FullPage" ID="FullPage" FrameType="TitleBarOnly"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td>
</tr>
<script type="text/javascript" language="javascript">if(typeof(MSOLayout_MakeInvisibleIfEmpty) == "function") {MSOLayout_MakeInvisibleIfEmpty();}</script>
</table>
</asp:Content>
<asp:Content>
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getUserData, "sp.js");
var context = null;
var web = null;
var currentUser = null;
function getUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onUserDataSuccess), Function.createDelegate(this, this.onUserDataFailure));
}
function onUserDataSuccess(sender, args) {
var user = web.get_currentUser();
alert('User name:' + user.get_title() + '\n Login Name:' + userObject.get_loginName());
}
function onUserDataFailure(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
</asp:Content>`enter code here`
You used <% ... %> which is C# code and cannot be used in JavaScript alone.
To get the current user's login name you will need to make use of the SharePoint ECMA script object model. To get the login name you can use the following script:
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getUserData, "sp.js");
var context = null;
var web = null;
var currentUser = null;
function getUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onUserDataSuccess), Function.createDelegate(this, this.onUserDataFailure));
}
function onUserDataSuccess(sender, args) {
var user = web.get_currentUser();
alert('User name:' + user.get_title() + '\n Login Name:' + userObject.get_loginName());
}
function onUserDataFailure(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
The important line is web.get_currentUser() which is the current user and afterwards you can do user.get_title(). Exactly in that onUserDataSuccess function you can do your redirect then.

Resources