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

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;
}
}
}

Related

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!

Button Event Code Behind not Firing on Azure

I have a fairly simple single page web application that I have fully tested locally. This application is a simple form submission, with the data being stored in a Azure Table Storage container.I have one code-behind function for the Submit button where I am doing server side validation with messages displaying in a pop-up window.
Everything works fine on my local machine, including all data storage and retrieval back to Azure. As soon as I publish the site to Azure, the code-behind will not fire and I am not getting any errors within the site itself. Any ideas?
Brian
Please see all the code below:
<form id="form1" runat="server">
<telerik:RadWindowManager ID="DefaultWindowMgr" runat="server"></telerik:RadWindowManager>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<div id="main" style="width:1024px; height:650px; margin-left:auto; margin-right:auto; background-image:url(../Images/earthBG.png);">
<div id="left" style="width:500px;float:left;left:5px;margin-left:auto;margin-right:auto;">
<asp:Image ID="Image1" runat="server" ImageAlign="Middle" ImageUrl="~/Images/TRACLogo.png" />
<asp:Image ID="Image2" runat="server" ImageUrl="~/Images/dashboardGlobe.png" ImageAlign="Middle" />
</div>
<div id="right" style="width:500px;float:right;top:75px;position:relative;">
<p>Some kind of Welcome Text needs to go here.</p>
<table id="RiskFormTable" style="width:100%;padding:5px;">
<tr>
<td style="text-align:right"><asp:Label ID="LblCompany" runat="server" Text="Company Name:"></asp:Label></td>
<td style="text-align:left"><telerik:RadTextBox ID="TxtCompany" runat="server" Width="220px"></telerik:RadTextBox></td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblEmail" runat="server" Text="Email Address of POC:"></asp:Label></td>
<td style="text-align:left"><telerik:RadTextBox ID="TxtEmail" runat="server" Width="220px"></telerik:RadTextBox></td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblCountries" runat="server" Text="What countries do you do business in?"></asp:Label></td>
<td style="text-align:left">
<telerik:RadListBox ID="LstCountries" runat="server" DataSortField="name" DataSourceID="XMLCountriesSource" DataTextField="name" DataValueField="score" Height="118px" SelectionMode="Multiple" Sort="Ascending" Width="220px" CausesValidation="False"></telerik:RadListBox>
</td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblPrimary" runat="server" Text="What is your primary customer segment?"></asp:Label></td>
<td style="text-align:left">
<telerik:RadComboBox ID="DDLPrimary" runat="server" Width="220px" DataSourceID="XMLSegmentsSource" DataTextField="name" DataValueField="value" CausesValidation="False"></telerik:RadComboBox>
</td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblSecondary" runat="server" Text="What is your secondary customer segment?"></asp:Label></td>
<td style="text-align:left">
<telerik:RadComboBox ID="DDLSecondary" runat="server" Width="220px" DataSourceID="XMLSegmentsSource" DataTextField="name" DataValueField="value" CausesValidation="False"></telerik:RadComboBox>
</td>
</tr>
<tr>
<td style="text-align:right" colspan="2">
<telerik:RadButton ID="BtnSubmit" runat="server" Text="Submit" SingleClick="true" OnClick="BtnSubmit_Click" CausesValidation="False"></telerik:RadButton>
</td>
</tr>
</table>
</div>
</div>
</form>
Here is the code behind:
using System;
using System.Configuration;
using TRACERiskLibrary.Entities;
using TRACERiskLibrary.Managers;
namespace TRACERisk
{
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// This function will get fired when a user submits the Risk Assessment data. It will verify that all of the
/// data is accurate and then will save the entry to the Azure Table that is found within the web.config file.
/// If any of the data is inaccurate or there is a problem with the saving of the data, the error will be
/// displayed to the user within the RadWindowManager Alert window.
/// </summary>
protected void BtnSubmit_Click(object sender, EventArgs e)
{
String azureconn = ConfigurationManager.ConnectionStrings["traceRiskAzure"].ConnectionString;
String azuretable = ConfigurationManager.AppSettings["AzureTable"];
if (TxtEmail.Text.CompareTo("") == 0 || TxtEmail.Text.IndexOf('#') < 0 || TxtEmail.Text.IndexOf('.') < 0)
{
DefaultWindowMgr.RadAlert("You must enter in a valid Email Address for this submission to be valid. Please try again.", 400, 250, "Risk Survey Submission Error", "");
return;
}
DellRiskEntity entity = new DellRiskEntity(TxtEmail.Text);
if (TxtCompany.Text.CompareTo("") == 0)
{
DefaultWindowMgr.RadAlert("You must enter in a Company Name for this submission to be valid. Please try again.", 400, 250, "Risk Survey Submission Error", "");
return;
}
else
entity.Company = TxtCompany.Text;
entity.PrimaryBus = DDLPrimary.SelectedItem.Text;
entity.PrimaryScore = (Int32) Decimal.Parse(DDLPrimary.SelectedValue);
entity.SecondaryBus = DDLSecondary.SelectedItem.Text;
entity.SecondaryScore = (Int32) Decimal.Parse(DDLSecondary.SelectedValue);
// Verify that the user entered in at least one country of business, if not throw up an error message and stop processing.
Int32 countryscore = 0;
if (LstCountries.SelectedItems.Count == 0)
{
DefaultWindowMgr.RadAlert("Please select one or more Countries for which you do business before submitting.", 400, 250, "Risk Survey Submission Error", "");
return;
}
else
{
for (int i = 0; i < LstCountries.SelectedItems.Count; i++)
{
entity.Countries.Add(LstCountries.SelectedItems[i].Text);
if (Int32.Parse(LstCountries.SelectedItems[i].Value) > countryscore)
countryscore = Int32.Parse(LstCountries.SelectedItems[i].Value);
}
}
entity.CountryScore = countryscore;
entity.TotalScore = entity.PrimaryScore + entity.SecondaryScore + entity.CountryScore;
if (entity.TotalScore < 11)
entity.TierLevel = "Tier 1";
else if (entity.TotalScore < 21)
entity.TierLevel = "Tier 2";
else
entity.TierLevel = "Tier 3";
// Process the actual saving of the Risk Assessment within the Azure Table
if (RiskManager.SaveEntry(entity, azureconn, azuretable))
DefaultWindowMgr.RadAlert("Your Risk Assessment has been Successfully submitted.", 400, 250, "Risk Survey Submitted", "");
else
DefaultWindowMgr.RadAlert("There is a record within the Risk Assessment associated with this email address. Please enter new Risk Assessment Data.", 400, 250, "Risk Survey Submission Error", "");
}
}
}

How to insert a custom label in between two fields in newform.aspx?

I have a form with many fields in it. I want to group 4-5 fields so that they can fall below the custom label. How to create this? I have very limited knowledge of coding.
I want to have custom labels like shown in the figure:
http://i45.tinypic.com/33agm0y.png
I picked up a coding from net and inserted it but it didn't work.
First, create your webusercontrol
WebUserControl1.ascx
This code is
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<asp:Label ID="label" runat="server" >
</asp:Label>
<table>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox5" runat="server"></asp:TextBox>
</td>
</tr>
</table>
Add this code behind for your usercontrol
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public string MyProperty { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
label.Text = MyProperty;
}
}
}
Secondly create your aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<%# Register TagName="test" TagPrefix="uc" Src="~/WebUserControl1.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:test id="uc1" runat="server" MyProperty="Texte1"></uc:test>
<uc:test id="uc2" runat="server" MyProperty="Texte2"></uc:test>
<uc:test id="uc3" runat="server" MyProperty="Texte3"></uc:test>
<uc:test id="uc4" runat="server" MyProperty="Texte4"></uc:test>
</div>
</form>
</body>
</html>

How to highlight a selected item in 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.

Resources