Catching the name of a button during post - asp.net-mvc

If I have an <input> of type submit, with a name, I can catch that name in my MVC model when I use it to post. Is the same not possible with a <button>, of type submit and the same name?
If I use for example name="ButtonName", my property ButtonName get's the input's value. For some reason this doesn't work with a button element.
The reason I want to use a button instead of input, is that i need to have more than text inside the button (including a picture).

You could set the value of the hidden input by using a simple onclick Javascript function for each of your inputs.
function setHidden(sender){
document.getElementById("hidden1").value = sender.value;
}

Related

Event for all Controls (Textbox)

I have many textboxes in my form and all of it have keypress.
Is there another way to shorten by code instead writing the code for each texboxes?
Thank You for your Answer.
You can create a subclass (let's call it subTB) of TextBox in which you define the action for keyPressed. Then make your TextBox be instances of subTB instead of instances of TextBox. You have a link to a tutorial in this comment.
Or you can create a function that contains the action to perform when a key is pressed. And the in all your textBox, on the key pressed event, call this function. This second choice will make you also write multiple time the same but this same code will just be a call to the function.

Value from dropdown on IconTabBar empty

change view (XML) contains IconTabBar with 3 IconTabFilters, which contain input controls (input, combobox, datePicker...). These input controls have pre-filled value from OData model. On the bottom of the view is button "Save". When I click on "Save" button, in my "onSave" function I am reading values from input controls from all IconTabFilters, but only values from the input controls on the first IconTabFilter are filled. Values from the rest of the fields are empty.
When I click on all IconTabFilters (without changing values), click "Save", then I'm getting all values correctly.
Please what I'm doing wrong? Odata model contains all required values, and also IconTabFilters contain all required values. But I can't read them from input controls before clicking on all IconTabFilters.
The Controls on the tabs only get initiated when they have to be displayed. This is done to improve the felt performance of the UI.
Since you are already using model binding, you should take the values out of the model instead of the input fields.

mvc razor default value on httppost for unselected radiobuttons

i have 2 radio buttons , which are optional, so by default no radio button is selected, if the user wants he can select the radio button. But on postback i should check whether the parameter entered by the user are same as the parameters defined in the application, for security.
There are other fields n the screen which are optional like textboxes, but textboxes are getting passed on httppost even when the user does not enter a value it is being passed as empty, but if user does not select radio button nothing is getting passed on postback, that field is missing in httppost.
Any work around to pass default value for unselected radio button on httppost.
You could place a "default" radio button, already selected, but not visible on your site ("style: display: none;"). That's the way ASP.NET works when you use some Html helpers like #Html.CheckBox(...) for instance: it places an invisible second checkbox with the same name, but containing the false value. It assures that a value will always be posted, even if the user doesn't check it (checkboxes, radio, etc are never sent with the form if they are not checked).

angularjs same textarea to edit multiple elements

I have this case where I set a current item from a list and I need to use a textarea to edit that element's value.
Because of some constraints I have to use a keyup event but I don't think that's a problem.
Check this fiddle: http://jsfiddle.net/terebentina/Euj2C/
click on first/second buttons - it works, it changes the text in the textarea to the value of each element.
change the text in the textarea to something
click on the first/second buttons again - the textarea is not updated anymore. If you look in console, you can see that it switches between the elements, it's just that the textarea is not updated anymore.
Any suggestions? this is driving me nuts!
I know there is a better way modifying your directive to do this but as a quick fix for now you can try binding your textarea to a ngModel value that is just a copy of the current text in the selected element:
<textarea keyup="" ng-model="keyupText"></textarea>
With this in as your current function:
$scope.current = function(idx) {
$scope.current_element = $scope.elements[idx];
$scope.keyupText = $scope.current_element.value;
console.log('current is', $scope.current_element.value);
}
See this fiddle for an example.

ViewBag values accessibility in mvc

The controller in which I define a viewbag value, returns a partial view, which is the last view that is beinng returned.
This partial view is rendered to a JQuery dialog. After I close it, I return to the one before, which contains a form. In the form view (the one before the last one) I'm trying to access the viewbag value via JS function, and assign it to a hidden field in the form. So actually, I'm trying to get the viewbag value, not from the view to which I've sent the viewbag.
Is it a problem? Are viewbag values available only from the last view that has rendered?
I'm not sure if it's possible, but in any case you wouldn't normally want or need to access ViewBag outside of the view it belongs to. It seems like there would be a couple of better options.
populate the ViewBag value you need into a hidden field somewhere else in the DOM.
Since you're using JQuery dialog, consider using its callback function to pass the values you need back to the main form. See here for an example: jquery ui dialog box need to return value, when user presses button, but not working

Resources