Well I have extensively used .NET and JQM. First with Web Forms, and now with ASP.NET Core.
Personally I went another direction than what you describe, for a number of reasons. Let me describe it here, and see if it is useful to you Sandy.
My first step was to drop the .NET postback alltogether and use Ajax method posts instead. When you use the Postback, you are effectively posting all data (viewstate) from the form to the server, and then recreating the web page again. That does not give you the best mobile experience, and you run in to issues as you described. I am not sure you can solve your need using JQM this way.
So I created a simple function PageMethod that I call when I want to handle the contents of the form, either at submit of the form, or after a change in an individual control. The function does the ajax call for all controls on the page. In the Web Form, I created WebMethods that handle the call:
For example, I have a case where the use makes a selection in a list, and then the second dropdownlist get filled based on the selection. The selection in this example is testId.
- PageMethod("Client.aspx/GetNormGroupsByTestID", {"testId":testId}, getNormsResponse)
Then in the .NET code I have a WebMethod:
- [WebMethod(EnableSession = true)]
- public static List<NormGroups> GetNormGroupsByTestID(string TestId)
- //called from script to get the Normgroups
- {
- .... prepare the list
- return normGroups; //return the list
- }
Then in Javascript I fill the second drop down list:
- function getNormsResponse(response) {
- //Get the Normgroup dropdown, this is the respons handler
- var normgroups = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
- var ddlNormgroups = $('#ddlNormgroups');
- ddlNormgroups.attr('disabled', false).children('option').remove();
- if (normgroups.length == 0) { ddlNormgroups.attr('disabled', true).append('<option value="0">Selecteer Vragenlijst...</option>'); }
- for (var i = 0; i < normgroups.length; i++) {
- var val = normgroups[i].NormGroupId;
- var text = normgroups[i].NormGroup;
- var def = normgroups[i].Default;
- ddlNormgroups.append('<option value="' + val + '">' + text + '</option>');
- if (def) { ddlNormgroups.val(val); } //set the default
- }
- }
Using .Net and JQM in this way allows you to use everything JQM has to offer, including the popups, styling, but also page transitions and even page caching.
I have now migrated the ASP.NET side to Asp.Net Core. Here you can do an even better and easier integration, because Asp.Net Core allows you to write native HTML, rather than controls that generate HTML. Again I use Ajax methods to communicate with the server, now through GET's or POST's to the controller:
in JS:
- PageMethod("ClientGetNormGroupsByTestID", { "testId": testId }, getNormsResponse, "GET")
and in c# on the controller:
- [HttpGet]
- public async Task<List<TblTestsNormGroups>> GetNormGroupsByTestID(string testId)
- {
- var user = await _userManager.GetUserAsync(HttpContext.User);
- return await TblTestsNormGroups.Find(testId, user);
- }
Hope this helps
Pieter