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();