26 Aralık 2012 Çarşamba

easy login mechanism for demo purposes

When you need to prepare a quick demo for a few users and you have not implemented your login mechanism yet, you can easily add forms authentication to you asp.net web application.

a simple login form (.aspx file)
<p>
        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
        <asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
    </p>
    <p>
        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
        <asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
    </p>

server side (aspx.cs file):
         protected void Page_Load(object sender, EventArgs e)
        {
            if (FormsAuthentication.Authenticate(this.UserName.Text, this.Password.Text))
            {
                FormsAuthentication.RedirectFromLoginPage(this.UserName.Text, true);
            }
        }

add the following lines to web.config file:
     <authentication mode="Forms">
      <forms loginUrl="~/menu/Login.aspx"  defaultUrl="~/menu/MenuMyApp.aspx" timeout="2880" cookieless="AutoDetect">
        <credentials passwordFormat="Clear">
          <user name="demo1" password="1"/>
          <user name="demo2" password="2"/>
        </credentials>
      </forms>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>

Your demo app is secure now.. Demo users can only login with the credentials specified.



15 Aralık 2012 Cumartesi

how to telerik:RadMenu show path


In order to view the selected path from your telerik RadMenu as in the picture below, you can use the following code:







aspx code:


<telerik:RadSiteMap ID="BreadCrumbSiteMap" runat="server" DataTextField="Text" DataNavigateUrlField="NavigateUrl">
        <DefaultLevelSettings ListLayout-RepeatDirection="Horizontal" SeparatorText="/" Layout="Flow" />
</telerik:RadSiteMap>



csharp code:


      protected void Page_Load(object sender, EventArgs e)
        {
            RadMenuItem currentItem = RadMenu.FindItemByUrl(Request.Url.PathAndQuery);
            if (currentItem != null)
            {
                currentItem.HighlightPath();
                DataBindBreadCrumbSiteMap(currentItem);
            }
            else
                RadMenu.Items[0].HighlightPath();
        }

        private void DataBindBreadCrumbSiteMap(RadMenuItem currentItem)
        {
            List breadCrumbPath = new List();
            while (currentItem != null)
            {
                breadCrumbPath.Insert(0, currentItem);
                currentItem = currentItem.Owner as RadMenuItem;
            }
            BreadCrumbSiteMap.DataSource = breadCrumbPath;
            BreadCrumbSiteMap.DataBind();
        }



The solution is from here: http://demos.telerik.com/aspnet-ajax/menu/examples/programming/showpath/defaultcs.aspx?Page=Blogs

13 Aralık 2012 Perşembe

using Telerik Scheduler to view weekly lesson plan


In this post, i present the code that configures Telerik radscheduler to view a weekly lesson plan. In order to do this, the selected date attribute should be a month starting at Monday (which is the first week day in the scheduler.)
.aspx code (actually i use it as a user control )
<telerik:RadScheduler runat="server" ID="RadScheduler" Width="750px" SelectedView="WeekView"
    TimeZoneOffset="00:00:00" SelectedDate="2013-04-01" DayStartTime="07:00:00" DayEndTime="23:59:00"
     ReadOnly="true"
     DataEndField="End" 
     DataKeyField="DersProgramiID" DataStartField="Start" DataSubjectField="DersItem" 
     AllowDelete="False" AllowEdit="False" AllowInsert="False" 
     DayView-DayStartTime="07:00:00" DayView-DayEndTime="23:59:00" LastDayOfWeek="Sunday" 
     WeekView-DayEndTime="23:59:00" WeekView-DayStartTime="07:00:00" WeekView-WorkDayEndTime="23:59:00" 
     WeekView-WorkDayStartTime="07:00:00" WorkDayEndTime="23:59:00" WorkDayStartTime="07:00:00" FirstDayOfWeek="Monday" 
     Height="900px" ShowNavigationPane="True" ShowAllDayRow="False" ShowHeader="False" ShowFullTime="False" ShowFooter="False" HoursPanelTimeFormat="HH:mm">
    <TimelineView UserSelectable="false" ShowDateHeaders="false"></TimelineView>
    <TimeSlotContextMenuSettings EnableDefault="true"></TimeSlotContextMenuSettings>
    <AppointmentContextMenuSettings EnableDefault="true"></AppointmentContextMenuSettings>
</telerik:RadScheduler>

csharp code to fill the scheduler:
 public void fill(List list)
 {
      this.RadScheduler.DataSource = list;
      this.RadScheduler.DataBind();

  }

The weekly lesson plan is as follows:

23 Ekim 2012 Salı

introduction to telerik reports

it has been years since i have not dealt with reporting.. so, i am a total newbie for this..
in this post, i share my one-day activity on warming up using telerik reports, a sample telerik report about a specific user's information viewed in a web app and how to deploy it in a remote server..
first thinngs first.. my bookmarks:

Report library part:
Now, the first step is creating a report library project.. Then a telerik report is created. i used the report wizard and used an SqlDataSource as the data source. My select query contains a parameter:
SELECT ...
FROM  ...  
WHERE TableStudent.ID = @StudentID
The report also contains a parameter with the same name. 
The constructor for the report is something like that:
        public ReportStudent(int studentID)
        {
            InitializeComponent();

            this.ReportParameters["StudentID"].Value = studentID;
            this.StudentDataSource.Parameters[0].Value = studentID;
            this.StudentDataSource.SelectCommand =           this.StudentDataSource.SelectCommand.Replace("@StudentID", studentID.ToString());
        }

Web app part:
In the web app which is going to view the report, i added a report viewer from the toolbox, but left the report property unassigned.  In the web page, the user selects a student, then presses a button and the report for the selected student is viewed inside the report viewer.
The button click event code is as follows:
protected void ButtonReport_Click(object sender, EventArgs e)
        {
            if (Session["StudentID"] != null &&
                !(((string)Session["StudentID"]).Trim().Equals("")))
            {
                ReportViewer viewer = (ReportViewer)this.ReportContent.Controls[0];
                ReportStudent report = new ReportStudent(Int32.Parse((string)Session["StudentID"]));
                viewer.Report = report;
                viewer.RefreshReport();
            }
        }

The above scenario works perfectly..
When deploying to the remote server, change the connection strings accoringly in:
  • Web.config of web app
  • Settings.settings and app.config for the report library.
Besides,  add the telerik libraries shown in the figure. (By the way, i am not sure if this list is minimal or not...)










and finally, here is telerik relevant portions of my web.config:



<configuration>
  <configSections>
    <section name="Telerik.Reporting" type="Telerik.Reporting.Processing.Config.ReportingConfigurationSection, Telerik.Reporting, Version=6.0.12.215, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>
  <Telerik.Reporting>
    <Extensions>
      <Render>
        <Extension name="IMAGE" visible="false"></Extension>
        <Extension name="HTML" visible="false"></Extension>
        <Extension name="MHTML" visible="false"></Extension>
        <Extension name="XLS" visible="false"></Extension>
        <Extension name="CSV" visible="false"></Extension>
        <Extension name="RTF" visible="false"></Extension>
      </Render>
    </Extensions>
  </Telerik.Reporting>
  ...
  <appSettings>
    <add key="Telerik.Skin" value="Web20" />
    <add key="Telerik.ScriptManager.TelerikCdn" value="Disabled" />
    <add key="Telerik.StyleSheetManager.TelerikCdn" value="Disabled" />
  </appSettings>
  <system.web>
    <pages>
      <controls>
        <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" />
      </controls>
    </pages>
    <compilation targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="Telerik.ReportViewer.WebForms, Version=6.0.12.215, Culture=neutral, PublicKeyToken=A9D7983DFCC261BE" />
        <add assembly="Telerik.Reporting, Version=6.0.12.215, Culture=neutral, PublicKeyToken=A9D7983DFCC261BE" />
      </assemblies>
    </compilation>
    <httpHandlers>
      <add path="ChartImage.axd" verb="*" type="Telerik.Web.UI.ChartHttpHandler"
        validate="false" />
      <add path="Telerik.Web.UI.SpellCheckHandler.axd" verb="*" type="Telerik.Web.UI.SpellCheckHandler"
        validate="false" />
      <add path="Telerik.Web.UI.DialogHandler.aspx" verb="*" type="Telerik.Web.UI.DialogHandler"
        validate="false" />
      <add path="Telerik.RadUploadProgressHandler.ashx" verb="*" type="Telerik.Web.UI.RadUploadProgressHandler"
        validate="false" />
      <add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource"
        validate="false" />
      <add path="Telerik.ReportViewer.axd" verb="*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=6.0.12.215, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"
     validate="true" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ChartImage_axd" />
      <add name="ChartImage_axd" path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" verb="*" preCondition="integratedMode" />
      <remove name="Telerik_Web_UI_SpellCheckHandler_axd" />
      <add name="Telerik_Web_UI_SpellCheckHandler_axd" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" preCondition="integratedMode" />
      <remove name="Telerik_Web_UI_DialogHandler_aspx" />
      <add name="Telerik_Web_UI_DialogHandler_aspx" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" preCondition="integratedMode" />
      <remove name="Telerik_RadUploadProgressHandler_ashx" />
      <add name="Telerik_RadUploadProgressHandler_ashx" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" preCondition="integratedMode" />
      <remove name="Telerik_Web_UI_WebResource_axd" />
      <add name="Telerik_Web_UI_WebResource_axd" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" preCondition="integratedMode" />
      <add name="Telerik.ReportViewer.axd_*" path="Telerik.ReportViewer.axd" verb="*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=6.0.12.215, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" preCondition="integratedMode" />
    </handlers>
  </system.webServer>
</configuration>