Monday, February 1, 2010

Get the text from dropdown in mvc asp.net

Get the value after dropdown value change.

there is very simple steps to get the dropdownlist value in controller at onChange event.

1) create the dropdownlist in .ASPX page.

Like:


id of the dropdownlist: ddl.
2) write the ajax call :


$(document).ready(function() {
$("#ddl").change(function() {
var text = $("#ddl> option:selected").attr("text");
$.ajax({
url: "/Controller/Action/",
data: 'ddlValue=' + text ,
type: 'GET',
dataType: 'html'
});
});

and the you can pass the ddlValue in the action method and you can get the text value of the drop down.

Hope its helpful. njoy the coding...




Monday, March 30, 2009

Create Simple MSMQ(MicroSoft Messaging Queue)

Here is simple msmq example with asp.net:

1) First install the messege queue from add windows component from control panal
Control Pannel--> Add or Remove Program-->Add/Remove windows componenets--->
Check the Messege Queue .

2) Create the new website using Microsoft developer studio

3) Add the textbox and labels to aspx page the to queue path and messeges like this














4) Now at .cs file first we import the namespace (System.messeging)
5) At rest of code like this:

protected void Button1_Click(object sender, EventArgs e)
{
MessageQueue mess = new MessageQueue(txtPath.Text);
Message myMessege = new Message(txtSend.Text
mess.Send(myMessege);
Response.Write("Messege Send Successfully!!!");
}

Now we are ready to create messege to messege queue.(Rememeber the path of messege queue is (.\private$\name of messege queue) and also make sure the messege queue should already exist)


Now Next Step is to create the Listner of the messege Queue .

1)Add new web page.

2) At .cs file use the following code:

At page load:

MessageQueue msmq = new MessageQueue(@".\private$\Test");(Name of Private Queue)
Message mess = new Message();
mess.UseDeadLetterQueue = true;
try
{
mess = msmq.Receive(new TimeSpan(0, 0, 30));
Type[] target = new Type[1];
target[0] = typeof(string);
mess.Formatter = new XmlMessageFormatter(target);
Label2.Text = (string)mess.Body;
}
catch (MessageQueueException eReceive)
{
Response.Write(eReceive.MessageQueueErrorCode.ToString());
Label1.Visible = false;
}

}


All the Best .

Happy Coding.