This project is read-only.

Passing parameters to survey control

Jan 17, 2008 at 9:03 PM
Newbie question...I'm building a survey system in which the answers have to be tied to a person's login. Can I pass the login string to the survey and have it end up in the result file?
Jan 22, 2008 at 6:17 AM
Edited Jan 22, 2008 at 6:18 AM
Yes, you can do this in an indirect way, using the "hidden questions features":

First, add a "hidden" question to your SurveyFile, as

<Question id = "hid" type = "hidden" />

(Note: id can be anything you want, and you can put
multiple hidden questions in a survey)

Then, in the Page_Load of your page, you can
retrieve a reference to this question and set it's
answer to anything you want (e.g. the login name of the user you want to track).

public void Page_Load(object server, EventArgs e)
// Check to see if survey has been taken.

HiddenWebQuestion hwq = (HiddenWebQuestion)ws.Questions["hid"]; // use the ID of the hidden question you want to access
hwq.SetAnswer("User's Login Here");

And that's all there is to it. You can store pretty
much any data you want in a hidden question, and you
can have several hidden questions in any given survey.

Hope this helps.
Aug 12, 2008 at 7:29 PM
I have tried the exact code above and can't get this working using the hidden questions feature.

I thought it had something to do with not initializing so I tried:

HiddenWebQuestion hwq = new HiddenWebQuestion("hid");
hwq.SetAnswer("User's Login Here");

I don't get an error but the hidden value is always blank in the answers file.

Not sure what I am doing wrong .. any help is appreciated.

-Steve W
Aug 15, 2008 at 9:34 PM
Try Page_PreRender instead of Page_Load and see if that solves the issue.

Aug 19, 2008 at 4:30 PM
Edited Aug 19, 2008 at 4:30 PM

wow.. that worked!  Thanks.    I guess I need to rewire my brain on what is considered "pre_render" worthy.   Page_Load seemed to be the logical place thus I never questioned it.  

Thanks again!