ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Is possible to extend a control?
Title:
B
I
{code}
?
Hi! I want to extend the funcionality of all my lookups for callback a js function with a json returned from the server. I know it is posible to do manually. But I have a lot of lookups and i don´t want to replicate this functionality in all lookups. My intention is to implement in this way: @Html.Awe().LookupFor(m => m.Meals).JsonCallBack("refreshFoods"). How can I do a custom extend for a LookUp? public class MyCustomLookupAttr<T> : Lookup<T> { private string jsonCallBack = string.Empty; private string url = string.Empty; public MyCustomLookupAttr<T> JsonCallBack(string jsFunc, string Url) { this.jsonCallBack = jsFunc; this.url = Url; return (MyCustomLookupAttr<T>)this; } internal override string Render() { string idField = "MealId"; //For example. string changeFunc = "mealChange"; string myCustomRender = "<script type='text/javascript'>" + " $(document).ready(function () {" + " $('#{0}').change({1});" + " }); " + " function {1}() {" + " var v = $('#{0}').val(); " + " $.getJSON('{2}/' + v, {3}); " + " }"+ "</script>"; return base.Render() + string.Format(myCustomRender, idField, changeFunc, this.url, this.jsonCallBack); } }
Save Changes
Cancel
sgambolati
asked at 17 Jan 2014
could please explain what are you trying to add, how will this functionality work from the user's pov ?
at 17 Jan 2014
Omu
I want to call a server action to retreive information in json, instead of call an action and retreive a pair id-name like now, and call a client-side function passing the json to refresh the UI (value of inputs and enable/disable/visible elements). I've done this functionality in very older version of Lookup control, and I'm upgrating to the lastest version and I'm lossing this key functionality. The simplest way I see is to extend the class LookUp to do this, doing in the same way Awe() controls set properties. But I can't "put"/extend the class.
at 17 Jan 2014
sgambolati
could you please explain from the user point of view what are you trying to build, and why do you need additional lookup functionality for it ?
at 17 Jan 2014
Omu
The user open the lookup, choose a row, and some controls in the page are visibled and anothers are invisibled.
at 17 Jan 2014
sgambolati
you can bind to the js change event of the lookup and show/hide depending on it's value, why do you need additional lookup functionality for this ?
at 17 Jan 2014
Omu
I know it. Inneed, I would do that. But I've a hundreds of lookup with that funcionality that I've got it with the old .aspx files with "open source".
at 17 Jan 2014
sgambolati
not sure how your additional functionality works but I think one script in Site.master should do it, something like $(document).on('change','.awe-lookup-field input', refreshfunc) you can also set html data attributes on each lookup and use them in the function, e.g. function rereshfunc(){ var myval = $(this).data('myattr'); }
at 18 Jan 2014
Omu
I know that is possible to do with js stuff, but I'm interesed to do this more efficently once on the 'control-extend-code' and forget until I want to change all the controls and not to change one by one on a modification. I would be happy if I can override the "render" method of the control to add my custom funcionality.
at 20 Jan 2014
sgambolati
you can't override render, but if you could what would you add ?
at 20 Jan 2014
Omu
If I could override render, I can add my custom implementation for example, the JsonCallBack I've asked.
at 21 Jan 2014
sgambolati
could you show the code
at 21 Jan 2014
Omu
edited question Implementation: @Html.Awe().MyCustomLookupAttr(x => x.MealId).JsonCallBack("refreshJsonData", "GetJson")
at 21 Jan 2014
sgambolati
it looks like you could just wrap it, create a new helper and call the lookup helper inside of it
at 21 Jan 2014
Omu
Can you please show how. Because that code does not compile because i cannot call an internal method like Render.
at 21 Jan 2014
sgambolati
something like: public static class MyHelpers { public static string MyLookup(this HtmlHelper html, string name) { return html.Awe().Lookup(...) + "my html"; } }
at 21 Jan 2014
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK