We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

QueryString in FormView

goodmanro
goodmanro asked
on
Medium Priority
1,617 Views
Last Modified: 2008-01-09
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?

Comment
Watch Question

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

FormView1.ChangeMode(FormViewMode.Edit)

Commented:
any luck?

Commented:
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.

Author

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?

Commented:
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

Author

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?

Commented:
sorry if this is a stupid question, but are all three of your templates configured?

Author

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!

Commented:
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>?
Commented:
also page loads normally have this on the end:
Handles Me.Load

let me know if any of this helps

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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 -
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.