View is null?

B

bshea

I have a form being built where I want to test for a field value and then
ensure the form's view is set correctly based on that value.

pseudo-code:
OnLoad()
{
check for status_field value
If (status_field value == "new") XDocument.View.SwitchView("Request");
.... more tests etc.

Problem:
When this occurs in the OnLoad function the view object is returning null
and then I can't test views, set views, etc.

Attempting to manually create a view object reference fails, with the same
result (obj doesn't exist or is null) but just on differentlines of code.

Any thoughts on how I can get the view to set correctly based on the field
value?
 
S

S.Y.M. Wong-A-Ton

Try

XDocument.ViewInfos["Request"].IsDefault = true;

instead of

XDocument.View.SwitchView("Request");
 
B

bshea

This seems to work, thanks! (still testing all my use cases but the initial
case tested success.

S.Y.M. Wong-A-Ton said:
Try

XDocument.ViewInfos["Request"].IsDefault = true;

instead of

XDocument.View.SwitchView("Request");

---
S.Y.M. Wong-A-Ton


bshea said:
I have a form being built where I want to test for a field value and then
ensure the form's view is set correctly based on that value.

pseudo-code:
OnLoad()
{
check for status_field value
If (status_field value == "new") XDocument.View.SwitchView("Request");
... more tests etc.

Problem:
When this occurs in the OnLoad function the view object is returning null
and then I can't test views, set views, etc.

Attempting to manually create a view object reference fails, with the same
result (obj doesn't exist or is null) but just on differentlines of code.

Any thoughts on how I can get the view to set correctly based on the field
value?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top