QueryString in FormView

I have this in my code behind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            If Request.QueryString("Mode") = "Insert" Then
                ProjectView.DefaultMode = FormViewMode.Insert
            ElseIf Request.QueryString("Mode") = "Edit" Then
                ProjectView.DefaultMode = FormViewMode.Edit
            Else
                ProjectView.DefaultMode = FormViewMode.ReadOnly
            End If
        End If
    End Sub

I am trying to call the QueryString Mode from another page to direct to the Insert View of the page.  On this page, I have this:

       <SelectParameters>
          <asp:QueryStringParameter DefaultValue="0" name="SiteID" QueryStringField="SiteID" />
          <asp:QueryStringParameter DefaultValue="ReadOnly" name="Mode" type="String" />
        </SelectParameters>

<asp:FormView DefaultView="ReadOnly" id="ProjectView" DataSourceID="DataConnection"  Runat="Server"
  AllowPaging="False"
  GridLines="None"
  HeaderStyle-ForeColor="#FFFFFF"
  HeaderStyle-Font-Bold="True"
  HeaderStyle-HorizontalAlign="Center">


However, when I call the Page.aspx?Mode=Insert - the ProjectView (FormView) does not display.  Any ideas?

goodmanroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ptleitchCommented:
try setting a default mode and then using the changemode command in your code

FormView1.ChangeMode(FormViewMode.Edit)
0
ptleitchCommented:
any luck?
0
bsdotnetCommented:
Currently, is ProjectView display readonly mode and blank?
a) please change DefaultView="ReadOnly" in your <asp:FormView> tag to DefaultMode=ReadOnly
b) do you have <InsertItem Template> section in your ProjectView?
       <asp:FormView DefaultMode=ReadOnly  id="ProjectView" ...>
            <EditItemTemplate>
               ...          
            </EditItemTemplate>
            <InsertItemTemplate>
                ...
            </InsertItemTemplate>
            <ItemTemplate>
                ...
            </ItemTemplate>
        </asp:FormView>
c) Lastly, when you view the page.aspx, make sure your url is .../Page.aspx?Mode=Insert
and the word "Insert" is case sensitve. "http://.../Page.aspx?Mode=insert" will NOT work.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

goodmanroAuthor Commented:
Ptleitch - I tried it, but no luck.

I tried:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            If Request.QueryString("Mode") = "Insert" Then
                'ProjectView.DefaultMode = FormViewMode.Insert
                ProjectView.ChangeMode(FormViewMode.Insert)
            ElseIf Request.QueryString("Mode") = "Edit" Then
                ProjectView.DefaultMode = FormViewMode.Edit
            Else
                ProjectView.DefaultMode = FormViewMode.ReadOnly
            End If
        End If


Bsdotnet - Yes, the FormView has an ItemTemplate, EditItemTemplate, and InsertItemTemplate.  The URL is also ProjectView.aspx?Mode=Insert (so its case sensitivity is correct).  I also changed DefaultView=ReadOnly.  Any other ideas?
0
ptleitchCommented:
i would recommend getting rid of the "ProjectView.DefaultMode = FormViewMode.Edit" altogether and replacing each and every one with the changemode command.  Define a default template, and anytime you want to change the mode to something else use changemode
0
goodmanroAuthor Commented:
So, I have this setup, but I'm still getting a blank FormView when I try to call ProjectView.aspx?Mode=Insert.  Technically, the QueryString variable should fire the ChangeMode Insert in this instance, but I'm not getting anything.  

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            If Request.QueryString("Mode") = "Insert" Then
                ProjectView.ChangeMode(FormViewMode.Insert)
            ElseIf Request.QueryString("Mode") = "Edit" Then
                ProjectView.ChangeMode(FormViewMode.Edit)
            Else
                ProjectView.ChangeMode(FormViewMode.ReadOnly)
            End If
        End If
    End Sub

Ideas?
0
ptleitchCommented:
sorry if this is a stupid question, but are all three of your templates configured?
0
goodmanroAuthor Commented:
Yes, I answered that above.

I have:

<asp:FormView DefaultView=ReadOnly id="ProjectView" DataSourceID="DataConnection"  Runat="Server"
  AllowPaging="False"
  GridLines="None"
  HeaderStyle-ForeColor="#FFFFFF"
  HeaderStyle-Font-Bold="True"
  HeaderStyle-HorizontalAlign="Center">  with the ItemTemplate, EditItemTemplate and InsertItemTemplate defined.  Order doesn't matter right?

Thanks!
0
ptleitchCommented:
try trouble shooting by eliminating the query string and just checking to see if your different templates appear on the page using no query string.  you could probably also try to pass the value to a session:

Session.Add("Mode", SomeControl)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Session("Mode") = "Insert" Then
ProjectView.ChangeMode(FormViewMode.Insert)
ElseIf Session("Mode") = "Edit" Then
ProjectView.ChangeMode(FormViewMode.Edit)
Else
ProjectView.ChangeMode(FormViewMode.ReadOnly)
End If
End If
End Sub

when you call these values from session, you might have to do something like this
dim strMode as String = CType(Session("Mode"), String)
and then ust strMode for the comparison
If strMode = "Insert" Then
why don't you post your code between <edittemplate> and <itemtemplate>?
0
ptleitchCommented:
also page loads normally have this on the end:
Handles Me.Load

let me know if any of this helps
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goodmanroAuthor Commented:
Ptleitch,
Thank you.  You were very helpful.  It always helps to have a second set of eyes.  I can't believe I missed that...

Thanks again -
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.