afrpa
asked on
Problem using the same formview within a webusercontrol multiple times on a page
First I'm using VS 2005 with AJAX, and I have a created a SQL Server 2008 Database to track some of our computer componet hardware.
I've created "Web User Controls" for nearly all my objects, and have placed them inside my monitors page. I have a button for editing a monitor and adding a monitor. Both Buttons open a ModalPopupExtension UpdatePanel that contain my WebUserControl. The WebUserContrl has a modified FormView for Editing and Inserting records in the Monitors table. I'm using Session parameters to of "MonitorEdit" to allow the webusercontrol on Page load to set the FormView1.DefaultMode = FormViewMode.????
My problem is getting the FormViews to switch from a "ReadOnly", "Edit", and "Insert" modes. It seems that the webusercontrol is being set for both popups on the initial load, and I have no way of changing them on the fly. I've read some articles about making the FormView properties public, but I'm unsure how to do that, and if that would even help. Below is my code, and hope this makes sense. Thanks for any help.
************************** ********** ********** ********** ***
<%@ Page Language="VB" MasterPageFile="~/AFRPA_Ad min.master " AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" title="Untitled Page" %>
<%@ Register Assembly="AjaxControlToolk it" Namespace="AjaxControlTool kit" TagPrefix="cc1" %>
<%@ Register Src="Controls/MonitorEdit. ascx" TagName="MonitorEdit" TagPrefix="uc2" %>
<%@ Register Src="Controls/gvMonitors.a scx" TagName="gvMonitors" TagPrefix="uc3" %>
<%@ Register Src="Controls/gvMonitorMod els.ascx" TagName="gvMonitorModels" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Cont entPlaceHo lder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="upEditMonitor" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc2:MonitorEdit ID="MonitorEdit2" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upAddMonitor" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc2:MonitorEdit ID="MonitorEdit1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upMonitors" runat="server">
<ContentTemplate>
<asp:Button ID="btnAddMonitor" runat="server" Text="Add Monitor" OnClick="btnAddMonitor_Cli ck" />
<br />
<br />
<asp:Button ID="btnEditMonitor" runat="server" Text="Edit Monitor" OnClick="btnEditMonitor_Cl ick" />
<br />
<br />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="btnAddMon itor"
BackgroundCssClass="modalB ackground"
PopupControlID="upAddMonit or" >
</cc1:ModalPopupExtender>
<cc1:ModalPopupExtender ID="ModalPopupExtender2" runat="server"
TargetControlID="btnEditMo nitor"
BackgroundCssClass="modalB ackground"
PopupControlID="upEditMoni tor" >
</cc1:ModalPopupExtender>
<uc1:gvMonitorModels ID="GvMonitorModels1" runat="server" />
<br />
<br />
<uc3:gvMonitors ID="GvMonitors1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
************************** ********** ********** ********** ****
Now Code behind on my Web Form:
Partial Class Test
Inherits System.Web.UI.Page
Protected Sub btnAddMonitor_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Session("MonitorEdit") = "Insert"
End Sub
Protected Sub btnEditMonitor_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Monitor_ID") = "1"
Session("MonitorEdit") = "View"
End Sub
End Class
************************** ********** ********** ********** ****
Now Code behind on my Web User Control:
Partial Class Controls_MonitorEdit
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("MonitorEdit") = "" Or Session("MonitorEdit") = "Insert" Then
FormView1.DefaultMode = FormViewMode.Insert
ElseIf Session("MonitorEdit") = "View" Then
FormView1.DefaultMode = FormViewMode.ReadOnly
ElseIf Session("MonitorEdit") = "Edit" Then
FormView1.DefaultMode = FormViewMode.Edit
End If
End Sub
End Class
************************** ********** ********
I've created "Web User Controls" for nearly all my objects, and have placed them inside my monitors page. I have a button for editing a monitor and adding a monitor. Both Buttons open a ModalPopupExtension UpdatePanel that contain my WebUserControl. The WebUserContrl has a modified FormView for Editing and Inserting records in the Monitors table. I'm using Session parameters to of "MonitorEdit" to allow the webusercontrol on Page load to set the FormView1.DefaultMode = FormViewMode.????
My problem is getting the FormViews to switch from a "ReadOnly", "Edit", and "Insert" modes. It seems that the webusercontrol is being set for both popups on the initial load, and I have no way of changing them on the fly. I've read some articles about making the FormView properties public, but I'm unsure how to do that, and if that would even help. Below is my code, and hope this makes sense. Thanks for any help.
**************************
<%@ Page Language="VB" MasterPageFile="~/AFRPA_Ad
<%@ Register Assembly="AjaxControlToolk
<%@ Register Src="Controls/MonitorEdit.
<%@ Register Src="Controls/gvMonitors.a
<%@ Register Src="Controls/gvMonitorMod
<asp:Content ID="Content1" ContentPlaceHolderID="Cont
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="upEditMonitor" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc2:MonitorEdit ID="MonitorEdit2" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upAddMonitor" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc2:MonitorEdit ID="MonitorEdit1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upMonitors" runat="server">
<ContentTemplate>
<asp:Button ID="btnAddMonitor" runat="server" Text="Add Monitor" OnClick="btnAddMonitor_Cli
<br />
<br />
<asp:Button ID="btnEditMonitor" runat="server" Text="Edit Monitor" OnClick="btnEditMonitor_Cl
<br />
<br />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="btnAddMon
BackgroundCssClass="modalB
PopupControlID="upAddMonit
</cc1:ModalPopupExtender>
<cc1:ModalPopupExtender ID="ModalPopupExtender2" runat="server"
TargetControlID="btnEditMo
BackgroundCssClass="modalB
PopupControlID="upEditMoni
</cc1:ModalPopupExtender>
<uc1:gvMonitorModels ID="GvMonitorModels1" runat="server" />
<br />
<br />
<uc3:gvMonitors ID="GvMonitors1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
**************************
Now Code behind on my Web Form:
Partial Class Test
Inherits System.Web.UI.Page
Protected Sub btnAddMonitor_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Session("MonitorEdit") = "Insert"
End Sub
Protected Sub btnEditMonitor_Click(ByVal
Session("Monitor_ID") = "1"
Session("MonitorEdit") = "View"
End Sub
End Class
**************************
Now Code behind on my Web User Control:
Partial Class Controls_MonitorEdit
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("MonitorEdit") = "" Or Session("MonitorEdit") = "Insert" Then
FormView1.DefaultMode = FormViewMode.Insert
ElseIf Session("MonitorEdit") = "View" Then
FormView1.DefaultMode = FormViewMode.ReadOnly
ElseIf Session("MonitorEdit") = "Edit" Then
FormView1.DefaultMode = FormViewMode.Edit
End If
End Sub
End Class
**************************
doh forgot to mention calling webcontrol.switchMode() from the button being pressed!
ASKER
mr nadger,
Thanks for your help, but the webcontrol is not getting the new session variable that I am setting when I click on the button. Could this be that the modalpopup is redering before the button onclick is run, or does the popupmodal null the button onclick?
Thanks for your help, but the webcontrol is not getting the new session variable that I am setting when I click on the button. Could this be that the modalpopup is redering before the button onclick is run, or does the popupmodal null the button onclick?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mr Nadger,
Thanks for the help. I finally figured it out and you put me in the right direction. I ended up having to set the modalpopupextender to open on a third, hidden box, so that the button would run first, then I would call the ModalPopupExtender1 to open.
Session("MonitorEdit") = "Insert"
MonitorEdit1.switchMode()
upAddMonitor.Update()
ModalPopupExtender1.Show()
Thanks for the help. I finally figured it out and you put me in the right direction. I ended up having to set the modalpopupextender to open on a third, hidden box, so that the button would run first, then I would call the ModalPopupExtender1 to open.
Session("MonitorEdit") = "Insert"
MonitorEdit1.switchMode()
upAddMonitor.Update()
ModalPopupExtender1.Show()
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
add another method to control the formview's mode (this is written on the fly but should give you the idea)
Public Sub switchMode()
Select Session("MonitorEdit")
Case "", "Insert"
FormView1.ChangeMode(FormV
Case "View"
FormView1.ChangeMode(FormV
Case "Edit"
FormView1.ChangeMode(FormV
End Select
End Sub
Put the webcontrol inside an updatepanel set to trigger on the button being clicked, and this should get you what you want
(I prefer using a case statement here as it's easier to follow the logic, but If's just as valid)