RSS

Monthly Archives: May 2014

Disable Textbox Paste Option in Winform


If you want to disable paste option on text box in Winform Application then this code very helpful for you.

Vb.Net
Private Sub txtbarcode_KeyDown(sender As Object, e As KeyEventArgs) Handles txtArabicName.KeyDown

If e.Control And e.KeyValue = 86 Then
e.Handled = True
e.SuppressKeyPress = True
End If
End Sub

 C#

private void txtbarcode_KeyDown(object sender, KeyEventArgs e)
{
	if (e.Control & e.KeyValue == 86) {
		e.Handled = true;
		e.SuppressKeyPress = true;


	}
}
Advertisements
 
Leave a comment

Posted by on May 27, 2014 in WinForm

 

Tags: , ,

How to disable the default Context Menu devexpress


If you want to Hide context menu on specific TextBoxt (Devexpress) Control then use this following Code,Write this code on Form Load Event

C#: 

ContextMenu emptyMenu = new ContextMenu();

this.components.Add(emptyMenu);

txtBardcode.Properties.ContextMenu = emptyMenu;

 VB.Net

 
Dim emptyMenu As New ContextMenu()

Me.components.Add(emptyMenu)

txtBardcode.Properties.ContextMenu = emptyMenu

 

 

 

ContextMenu

 
Leave a comment

Posted by on May 27, 2014 in WinForm

 

Tags: , ,

Multiple GET methods in ASP.NET Web API


The default  controller web api gives you has the following pattern The built in GET,POST,PUT convention that web API.supports .I have found to support extra GET methods and support the normal REST methods as well.

public class MyController : ApiController
    {
        // GET api/test
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }
 
        // GET api/test/5
        public string Get(int id)
        {
            return "value";
        }
 
        // POST api/test
        public void Post([FromBody]string value)
        {
        }
 
        // PUT api/test/5
        public void Put(int id, [FromBody]string value)
        {
        }
 
        // DELETE api/test/5
        public void Delete(int id)
        {
        }
    }

the Problems start  when you want to define more than one  “GET” method that goes by a different name.which always get one method & give Error.

  public class MyController : ApiController
    {
        // GET api/test
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }
 
        // GET api/test/GetAllWithFilter
        [HttpGet]
        public IEnumerable<string> GetAllWithFilter()
        {
            return new string[] { "value1"};
        }
 
        // GET api/test/5
        public string Get(int id)
        {
            return "value";
        }
 
        // POST api/test
        public void Post([FromBody]string value)
        {
        }
 
        // PUT api/test/5
        public void Put(int id, [FromBody]string value)
        {
        }
 
        // DELETE api/test/5
        public void Delete(int id)
        {
        }
    }

This shouldn’t be that hard to fix on the surface but the built in route that enables this convention.I searched around for a while to figure out how to solve this then finally ran across a great Stackoverflow post here that nails it and http://lonetechie.com/2013/03/04/fixing-multiple-actions-were-found-that-match-the-request-aspnet-webapi/.

Replace your built in route in WebApiConfig with this (updated for latest release).

 config.Routes.MapHttpRoute("DefaultApiWithId", "api/v1/{controller}/{id}",
 new{ id = RouteParameter.Optional}, new{ id =@"\d+"}); 

config.Routes.MapHttpRoute("DefaultApiWithAction", "api/v1/{controller}/{action}"); 

config.Routes.MapHttpRoute("DefaultApiGet", "api/v1/{controller}",
 new{ action ="Get"}, new{ httpMethod =new HttpMethodConstraint(HttpMethod.Get)}); 

config.Routes.MapHttpRoute("DefaultApiPost", "api/v1/{controller}",
 new{ action ="Post"}, new{ httpMethod =new HttpMethodConstraint(HttpMethod.Post)});

 config.Routes.MapHttpRoute("DefaultApiPut", "api/v1/{controller}", 
new{ action ="Put"}, new{ httpMethod =new HttpMethodConstraint(HttpMethod.Put)}); 

config.Routes.MapHttpRoute("DefaultApiDelete", "api/v1/{controller}", 
new{ action ="Delete"}, new{ httpMethod =new HttpMethodConstraint(HttpMethod.Delete)});

 


 
Leave a comment

Posted by on May 21, 2014 in MVC, Web API

 

Tags: ,