views:

513

answers:

4

Hi everyone,

i am trying to access the contents on my textbox while on the page. is there anyway of doing that ?

Thanx

Owais

A: 

Using Jquery you can do something like this:

$("#MyTextBoxId").Val()

Micah
A: 

It depends on what you intend to do with the data. If you need to manipulate it on the client, the the jquery reference is appropriate. If you need to pass it to some business logic in your model, then the appropriate controller action is the place to do it. From the controller action you have access to the request object, which will have the text box's value. Additionally, if you've got a model object that corresponds to the text box's ID, you can use the UpdateModel function to map the values automatically.

bxlewi1
maybe i am very far off ..i tried doing this but nothing happened..Html.ViewContext.Controller.ControllerContext.HttpContext.Request["Calendar_Type"]
devforall
A: 

If you want the contents of yout textbox on a submit then you should have a method in your controller which accepts the item as a parameter. For example, if your form has the textbox with id "myText" your controller should look something like:

[ActionName("WhateverYourShowFormActionIsCalled"), AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyControllerAction(string myText)
{
    //Do stuff with myText
}
Wolfwyrd
A: 

This has to be done on the client side. You could, however, send an AJAX request if the server requires the information. Examples in Scriptaculous/Prototype
One-way

function send() {
    var val = $F('textBoxName'); // put own here
    var url = "/ajax/textboxupdate"; // put own here
    Ajax.Request ( url,
        { method: 'get',
          parameters: {'val':val},
          onSuccess: new function(tr) { success(tr); }
    });
}

For two-way, use the tr.responseText parameter. (API ref)
ASP.NET AJAX could also be used - see the website.

Lucas Jones