Is there any way other than Ajax request to autopostback the form when the selectd index of a combobox is changed?
I dont want to perform ajax requests to call the methods explicitly, Isnt there an onchange() attribute which will post the form(this.form.submit()) when the index is changed without clicking the submit button.
Also in my igCombo I cannot define it like this :
THIS DOESNT WORK:
@using (Html.BeginForm()) { @(Html.Infragistics().Combo("comboProducts") // When I supply it with id, I get object not set to an instance of an object exception)
}
THIS WORKS:
@using (Html.BeginForm()){
@(Html.Infragistics().Combo() //This works but I think the ID of / <select> element is not set , rather / <span> gets the id. .InputName("comboProducts") .ID("comboProducts") //is this the same id which gets supplied to .Combo("id")??
) }
--------------------------------------------------
Because of this issue, I think I am also unable to persist the selected value of igCombo on postback.
Please help me out here.
Hello Omer ,
Thank you for posting in our forum.
I’ve tested how the editor behaves when the id is set as follows: @(Html.Infragistics().Combo("combo1") …
However I didn’t get any errors when testing this on my side.
In general the combo does have events you can use to trigger a submit. For example you can use the DropdownClosed event and in it force the form to submit:
$(document).delegate("#combo1", "igcombodropdownclosed", function (evt, ui) {
$("form")[0].submit();
});
Then on the Action associated with the form you can get the passed value from by passing a variable with the same name in the Action:
public ActionResult SaveData(string combo1)
{
…
If you need to persist the selection over postbacks I recommend that you associate the Combo with a property from your Model.
For example : @(Html.Infragistics().ComboFor(a => a.SelectedValue)
Then on the Action triggered on submit you can return the same view and in the model pass the value for the current Selected Value:
public ActionResult SaveData(string SelectedValue)
igCombo_example_form.Models.ComboModel model = new igCombo_example_form.Models.ComboModel();
List<Product> prod = new List<Product>();
for (int i = 0; i < 20; i++)
prod.Add(new Product() { ID = i, ProductName = "Prod Name" + i });
model.Products = prod;
model.SelectedValue = SelectedValue;
return View("Index",model);
I’ve attached a sample for your reference. Please refer to it and let me know if you have any questions.
Best Regards,
Maya Kirova
Developer Support Engineer II
Infragistics, Inc.
http://es.infragistics.com/support
I dont want to use ComboFor() because this would require me to provide the model using the @model directive at the top.
In my case the igCombo is in a partial View & the parent View is already getting a @model Infragistics.Web.Mvc.GridModel on top therefore I cannot supply it with another comboModel. Therefore I was hoping to do the same thing using @(Html.Infragistics().Combo("Combo1") & supply it with DataSourceUrl instead of DataSource, BUT I cannot set the id of the combo which is causing issues i think.
One quick question:
Is this the same : @(Html.Infragistics().Combo().ID("Combo1") as this : @(Html.Infragistics().Combo("Combo1") ??
Hello Maya,
I am able to persist the combo selection as well as do autopostback.
For AutoPostback:
I was getting null reference exception when i supplied id like this @(Html.Infragistics().Combo("combo1")
Now I am using this @(Html.Infragistics().Combo().ID("combo1") to set the id & use the Id in delegates as parameter & the form is posting itself back just fine
For Persisting Combo Selection:
The main culprit was : public ActionResult Listing(int[] comboProducts) instead of public ActionResult Listing(string[] comboProducts)
My ValueKey was a string & I was specifying int[] in the [HttpPost] method because i thaught this would get the selected indexes of the combo, rather it gets the ValueKey itself.
Thanks alot for your help & time.
Yes. Both will lead to the same result.
Both:
@(Html.Infragistics().Combo("combo1")
And
@(Html.Infragistics().Combo().ID("combo1")
Will generate a span element with the related id that will be the main Dom element of the combo.
In both cases the selector for the combo would need to be “#combo1”.
Let me know if you have any additional questions.