Hi Friends,
I am currently working on maintenance of existing CMS system from our company.
Yesterday client came up with an interesting bug, the dynamic forms generated via CMS has just stopped working
I investigated for more than couple of hours to find out what’s wrong.
In our CMS there is a module of dynamic forms, which generates forms runtime by getting information of forms from an XML file and this form could be added to any page while generating pages from template, and on submission of this form from end users all fields are getting stored in database.
It just posts data to an aspx page, which first identifies for which form this submission has made by looking at hidden field which contains form’s id and then it gets details of this form and then stores all the values to database.
Its not as simple as it looks by this description, it contains form field’s validation by javascript, CAPTCHA validation etc. All this is handled by an aspx page.
Now let come to the problem, the problem was after renewing all templates and frontend, client has introduced asp.net Ajax to all pages and so all pages has an Ajax script manager on page following form tags. The form tag is now on every page as direct child of body tag.
Now when form is generated and rendered to this page there will be 2 forms on page, the main form and this dynamic form which is placed inside main form. So it has to fail anyway
So how to solve this??
There is a way, still our form is generated dynamically and does not contain any form fields as server side control we can do this.
There is an option in asp.net to submit a form to different page then the control is placed on(Cross page posting), the option is : PostBackUrl=”~/TargetPage.aspx” this option is available for all controls which are capable to fire server side request/event.
Now how to use this option to the controls that are generated dynamically and are not server controls!!
Yeah, so what I did was:
Created a temp page with this option, I viewed source code to find out how this stuff works, I found an interesting thing:
onclick=’WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(\”btnSubmitToForm\”, \”\”, false, \”\”, \”/TargetPage.aspx\”, false, false));’
This JavaScript makes POST request to mentioned page, I did the same to my form and it works!!!
To make this thing work you would have to set enableViewStateMac=”false” in web.config (or page level should also work!)
So that was good option in asp.net which saved my life!!
Let me know if any problem
-
Vipul Limbachiya
VN:F [1.9.3_1094]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.3_1094]