Sunday, March 31, 2013

android app dev assign int value to a TextView

This is rather wierd, when you want to assign an integer to a TextView apparently you need to assign the combination of "" +  and your integer value.


e.g. 
myTextView = (TextView) findViewById(R.Id.myTextView);
myTextView.setText(""+myIntegerValue);

Thursday, March 21, 2013

asp.net webforms app with mvc, unable to find "/Account/Login"

I have an asp.net webforms application with later on added mvc component. The login view is embeded inside the homepage Default.aspx. When I type into browser and try to open a login controlled URL without loggged in, i should be redirected to the Default.aspx homepage for login, but instead I get 404 not found error looking for "/Account/Login".

The solution worked for me is rather wierd:
add the following setting in AppSettings section of your web.config



Wednesday, March 20, 2013

radgrid initial filter


if (!page.ispostback)
{

RadGrid1.MasterTableView.FilterExpression = "([Country] LIKE \'%Germany%\') ";
        GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Country");
        column.CurrentFilterFunction = GridKnownFunction.Contains;
        column.CurrentFilterValue = "Germany";
        RadGrid1.MasterTableView.Rebind();
}

Friday, March 15, 2013

tsql find table name by index name


EXEC sp_MSforeachdb 'USE ?
select ''?'' as DatabaseName, st.name as TableName,si.name as IndexName from sys.indexes si
inner join sys.tables st
on
si.object_id = st.object_id
where si.name like ''%NC_explore_user%'''

Monday, March 11, 2013

deploy mvc 4 razor application onto shared hosting 404 default document not found error

the solution for me is to have this under


also you need to make sure your hosting environment is setup for .net v4.x and integrated mode

Sunday, March 10, 2013

mvc temperary value options

ViewData/ViewBag : only eixsts for single controller request on single view


TempData: exists beyond single controller request inside same controller, expires once the value is requested

Session: exists for multiple controller requests within same controller, expires once navigated away to other controller

Monday, March 04, 2013

mvc 4 custom server validation on multiple fields

Imaging there is a many to many relationship between category and product and there are some specific information required on this many to many relationship, therefore we need a dedicated entity CategoryProduct to work with. On submission I need to validate whether the combination of category and product selections already exist.

in validation controller provide:


public JsonResult ValidateCategoryProduct(int? categoryProductId, int categoryId, int productId)
        {
            if (!categoryProductId.HasValue)
            {
                categoryProductId = -1;
            }

            var validationResult = categoryProductRepository.ValidateCategoryProduct(categoryProductId.Value, categoryId, productId);
            if (validationResult)
            {
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            else
            {
                string output = "This category product relationship has already been setup.";
                return Json(output, JsonRequestBehavior.AllowGet);
            }
        }

in my model I have


[DisplayName("CategoryId")]
        [Remote("ValidateCategoryProduct", "ValidationLogic", AdditionalFields = "CategoryProductId,ProductId")]
        [Editable(true)]
        public int CategoryId { get; set; }

        [DisplayName("ProductId")]
        [Required(ErrorMessage = "Please select a Product")]
        [Remote("ValidateCategoryProduct", "ValidationLogic", AdditionalFields = "CategoryProductId,CategoryId")]
        [Editable(true)]
        public int ProductId { get; set; }

in my view I have the following under the category textbox
@Html.ValidationMessageFor(model => model.CategoryId, "*")
I also have the following under the productid textbox
@Html.ValidationMessageFor(model => model.ProductId, "*")

now we are good to go, the only issue left is that we need to figure out a way to apply validation result to both properties at once..... puzzled at the moment.

Friday, March 01, 2013

KendoUI Grid MVC4 hide delete button in the list if there is depent records




.CellAction(cell=>{
                     if (cell.Column.Title == "Delete" && cell.DataItem.ChildRecords.Count > 0)
                     {
                         cell.HtmlAttributes["style"] = "visibility:hidden";
                     }
                 })

alternatively:


columns.Template(
                          @@Html.ActionLink("Delete", "Delete", new { id = item.ChildRecordId}, (item.ChildRecords.Count > 0 ? new {style = "display: none"} : null))
                          ).Title("Delete");

raddatepicker get selected date client side into a string

RadDatePicker1.get_dateInput().get_selectedDate().format("dd/MM/yyyy");

radtextbox get value from client side


$find("<%= RadTextBox1.ClientID %>").get_value();

Monday, February 04, 2013

aspx dropdownlist get selected text from client side using javascript

$('[id*=ddlCountry] option:selected').text()

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