Tuesday, January 22, 2013

asp.net membership default setup

with these settings inside   you are set to go.


tsql add default constraint



IF NOT EXISTS(select * from sys.DEFAULT_CONSTRAINTS where NAME like 'def_myconstraint1%')
BEGIN

 ALTER TABLE mytable1
 ADD CONSTRAINT def_myconstraint1 DEFAULT 1 FOR mycolumn1
END
GO

Friday, January 18, 2013

css center a div

tried to use text-align:center didnt work, the correct way is:

width: 10240px ;
  margin-left: auto ;
  margin-right: auto ;

Saturday, January 12, 2013

asp.net web application update web.config SMTP settings in global.ascs application_start():

asp.net web application update web.config SMTP settings in global.ascs application_start():


System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
            System.Net.Configuration.MailSettingsSectionGroup mailSettingsGroup = config.GetSectionGroup("system.net/mailSettings") as System.Net.Configuration.MailSettingsSectionGroup;
            mailSettingsGroup.Smtp.Network.Host = Properties.Settings.Default.SMTPServer;
            mailSettingsGroup.Smtp.Network.Port = Properties.Settings.Default.SMTPPort;
            mailSettingsGroup.Smtp.Network.DefaultCredentials = Properties.Settings.Default.SMTPAuthenticationEnabled;
            if (mailSettingsGroup.Smtp.Network.DefaultCredentials)
            {
                mailSettingsGroup.Smtp.Network.UserName = Properties.Settings.Default.SMTPUsername;
                mailSettingsGroup.Smtp.Network.Password = Properties.Settings.Default.SMTPPassword;
            }

Wednesday, January 09, 2013

prevent double click on asp.net button control

headache solved after search and search and search for solutions:

OnClientClick="this.disabled = true; this.value = 'Submitting...';__doPostBack('SaveChangesButton','')"

Wednesday, December 26, 2012

asp.net Response.RedirectToRoute issue

In my global.ascx I have the routing setup: 
routeCollection.MapPageRoute("My Home Page", "myhomepage/{myid}", "~/MyHomePage.aspx");
I use Response.RedirectToRoute() with a parameter to open a page. I identified that in the following cases the redirect will fail:
  • The parameter is not given. e.g. Response.RedirectToRoute("My Home Page");
  • The parameter as null value. e.g. Response.RedirectToRoute("My Home Page", new {myid = null});
  • The parameter as null value. e.g. Response.RedirectToRoute("My Home Page", new {myid = string.empty});

Apparently you MUST give a non-empty value to the parameter.

regular expression for character range

regular expression for character range:
e.g. between 1 and 500:
^.{1,500}$

Thursday, December 20, 2012

fix asp.net checkboxlist wierd layout

on one page my checkboxlist shows up correctly, on another it never does. After hours of trying I figured this out: assign CheckBoxList class to your css class of the checkboxlist, play with the properties inside the class will help you fix the issues.


         .CheckBoxList input
        {
            margin-left: -10px;
        }
        .CheckBoxList td
        {
            padding-left: 10px;
            width:80%;
        }

t-sql change a column from nullable to not null and add default value it


--1.make sure all records have a value in the column
update [TableName]
SET [ColumnName] = [Default Value]

--2. change the column to not null
ALTER TABLE [TableName]
ALTER COLUMN [ColumnName] [data type] NOT NULL
GO

--3. add default value constraint to the column
ALTER TABLE [TableName] WITH NOCHECKADD CONSTRAINT [DF_DefaultName] DEFAULT [Default Value] FOR [ColumnName]
GO

Wednesday, December 05, 2012

jquery to check if an asp.net checkbox control is selected or unselected:

$('input[id$=cb1]').is(':checked'){
          //your code here
}

Saturday, November 24, 2012

Telerik OpenAccess Service works locally but not hosted

I have 3 projects, one with the entity model, another one with the OData v3 service generated from the entity model, the third one is an asp.net web application.

During local development the service reference I added into the web app is from same solution: http://localhost:55001/MyModelService.svc

After everything was successfully tested I then published the service project and hosted it on a third party hosting service. I was able to browse the service successfully by going: http://service.myapp.com/MyService.svc

I then re-added the existing service reference into my web app with the remote url shown above, published the web app on another hosting service.

When I load up the web app I got an error:
DataServiceQueryException was unhandled by user code
An error occurred while processing this request.

The issue turned out to be really fundamental which I missed out through all my WCF learnings: the cross domain policy xml!

The solution is to add a clientaccesspolicy.xml into the OpenAccess Service WCF app root folder with the following content:



Wednesday, August 22, 2012

Friday, August 03, 2012

MS Office EXCEL 2010 the safest way to open .csv file and maintain leading zeros

Step 1:
Open EXCEL, click on tab "Data", select "From Text".

Step 2:
Browse to your local file folder and open the .csv file.

Step 3:
In the "Text Import Wizard - Step 1 of  3" popup, select "Delimited" and click on "Next".



Step 4:
In the "Text Import Wizard - Step 2 of  3" popup, select "Comma", un-select all other options, and click on "Next".



Step 5:
In the "Text Import Wizard - Step 3 of  3" popup, in "Data Preview" click to select the column you want to maintain leading zeros, then select "Text" in "Column data Format", now click on "Finish".




Step 6:
In the "Import Data" popup click on "OK".


Now you can see all leading zeros in EXCEL!

Thursday, July 12, 2012

get selected values form a checkboxlist c# asp.net web application

List selectedRoles = cblRolesAdd.Items.Cast().Where(n => n.Selected).Select(n => n.Value).ToList();

Wednesday, June 20, 2012

asp.net c# write to txt file


string path = HttpContext.Current.Server.MapPath("~/xxxxxxxx.txt");
                if (!System.IO.File.Exists(path))
                {
                    // Create a file to write to.
                    using (StreamWriter sw = System.IO.File.CreateText(path))
                    {
                        sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------");
                        sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------");
                        sw.WriteLine("------------------------Some explanation of the purpose of this file-----------------------------");
                        sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------");
                        sw.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------");
                    }
                }
                using (StreamWriter sw = System.IO.File.AppendText(path))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
                    sb.AppendLine("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
                    sb.AppendLine("WHEN: " + DateTime.Now.ToString());
                    sb.AppendLine("WHO: " + GetCurrentUser());
                    IPHostEntry host;
                    host = Dns.GetHostEntry(Dns.GetHostName());
                    foreach (IPAddress ip in host.AddressList)
                    {
                        if (ip.AddressFamily.ToString() == "InterNetwork")
                        {
                            sb.AppendLine("WHERE: " + ip.ToString());
                            break;
                        }
                    }
                    sb.AppendLine("WHAT: " + errorMsg);
                    sb.AppendLine();
                    sb.AppendLine();
                    sb.AppendLine();
                    sw.WriteLine(sb.ToString());
                }


Tuesday, June 19, 2012

.NET Web Application install default SqlMembershipProvider schema

find and run the following executable inside "%Windows\Microsoft.NET\[framework number]\[version number]\"

aspnet_regsql.exe

Friday, June 15, 2012

RadGrid ItemCommand Find Control

if the control you are looking for is a button:
((Button)e.CommandSource)


if the control you are looking for is a label:
((Label)e.CommandSource)

Thursday, June 14, 2012

RadWindow Resize by Percentage


var width = $telerik.$(window).width() * 0.8;
                    var height = $telerik.$(window).height() * 0.95;
                    ExpWindow.setSize(width, height);
                    ExpWindow.center();

StimulSoft Report Web Designer Save Report

protected void StiWebDesigner1_SaveReport(object sender,

StiWebDesigner.StiSaveReportEventArgs e)
{
StiReport report = e.Report;
        string file = report.ReportFile;
        report.Save(file);
}