Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent help - Form not submitting values.

Status
Not open for further replies.

Dobly

Programmer
Joined
Oct 11, 2003
Messages
7
Location
AU
Help!. I need help with a form on a site I am building in C#.NET. The structure of the site is done. It is complex system that goes through the following steps..

1. Reads a template file (the pages main HTML code)
2. Parses the code, outputting most of it to a HtmlTextWriter object and looking for special tokens that I put in. A typical 'token' is the the one called 'sidenav'. (this one writes out the side navigation on the page)
3. Once a token is found, the matching user control is loaded, with this code...

Controls.AddAt(0, LoadControl(strUserControl));
Controls[0].RenderControl(writer);
base.Controls.Remove(base.Controls[0]);

This code is called from an override of the Render and OnPreRender classes, in the file called BasePage, (that is inherited by every page on the site).

One of the usercontrols that gets loaded is called 'survey'. This user control, will load one of 4 user controls that each have a form in them (parts 1-4 of a survey).

The 'survey' user control uses this code to load the approprate user control.....

Control control = LoadControl (Session["SurveyForm"].ToString() + ".ascx");
lblSurveyForm.Controls.Add (control);

Where Session["SurveyForm"] might equal 'survey1', the first time in.

In the user control survey1.ascx, there is a form. This, is the only form on the site at this point in time. (good, as .net cannot do more than one form that has runat='server' set.).

The problem is this. I can hit the 'next>' button on the form which submits it, the page reloads, as if it submitted, but no values are submitted. Not only that, but Page.IsPostBack equals false, no matter how many times I submit the form. Therefore I am not given a chance to request the values out of the form.

There must be solution to this. I cannot believe that .NET cannot process a form that is loaded from a dynamically loaded user control.

Could the problem be that i am not using a HTMLTextWritter object in the second instance? (If it is, now do I do that? I only seem to be able to get it working in the Render method)

Any help with this would be greatly appriciated.

Thanks in advance.
 
I have another odd thing to add. I have just noticed, doing 'View Source' on my rendered page, that the form has no VIEWSTATE set. Odd no?

One final thing, is that in my code I declare the form like this..

<form method=&quot;post&quot; runat=&quot;server&quot; id=&quot;SurveyForm1&quot;>

and .NET renders it like this....

<form name=&quot;_ctl5:_ctl0:_ctl0:DonateForm1&quot; method=&quot;post&quot; action=&quot;p.aspx?n=LAFEP-KXTHT-LORGQ-WFWEJ-GARSU&quot; id=&quot;_ctl5__ctl0__ctl0_DonateForm1&quot;>

You can see here just how deep in nested user controls my form is.
 
oops, wrong form name in the above page.. (is there an edit function in the forum).
The correct code should have been....

<form name=&quot;_ctl5:_ctl0:_ctl0:SurveyForm1&quot; method=&quot;post&quot; action=&quot;p.aspx?n=LAFEP-KXTHT-LORGQ-WFWEJ-GARSU&quot; id=&quot;_ctl5__ctl0__ctl0_SurveyForm1&quot;>

(this is not the problem with my app, and is just a problem with the above post.
 
I have more news on this problem.

I moved the project to a different environment. This one a win2000 server, as opposed to the winXP server I was on before.

The error is still there, but it behaves differently.

On the win2000 server, the form returns an error when you hit the button. The error is....

&quot;The viewstate is invalid for this page and might be corrupted&quot;

Going back to the form page and viewing its source code, I see this...

<input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; value=&quot;&quot; />

NO VALUE!!

On the winXP server it does not write out this line at all.

I susspect it is the same probem on both... just WHAT is the problem?
 
I have this problem fixed now. The form is submitting and has values in it, problem is that I cant read them.. I am starting a new post with this new problem..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top