Solved

Problem updating database from inside an IFRAME

Posted on 2003-11-24
3
424 Views
Last Modified: 2011-09-20
I'm kinda new to .net development so excuse med if this is silly question. I have an aspx page which contains a DataList that gets values from an sql server. Based on these values I am going to show a new aspx page which contains a datagrid and do some database operations. I initially displayed the new datagrid in a pop up window and it all worked fine! However due to design issues I now have to display the aspx page/grid inside an <IFRAME> on the same page which I show/hide based on a button click. This all works!
The real problem is that the database operation that is supposed to happen inside the IFRAME doesn't work.
The button event of this grid don't seem to fire for some reason. When i press the button everything seems  
to be working correctly and no errors are showing, but the updates doesn't appear in the database?
Is this because the grid is inside an IFRAME? Is it at all possible to do this way?  

Any suggestions would be greatly appriciated!

<CODE>

//this is the page that contains the IFRAME
<asp:DataList id="DataList1" Width="100%" Runat="server"
OnItemCommand="DataList1_ItemCommand"
OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>                                          
      <table border="1" cellpadding="0" cellspacing="0" width="100%">
      <tr>
      <td align="left" width="10%">
      <asp:Label ID="Label2" Runat="Server" Text='<%# Container.DataItem("CompLinkID") %>' ></asp:Label>
      </td>
      <td align="left" width="10%">
      <%# Container.DataItem("CompName") %>
      </td>
      <td align="left" width="50%">
      <asp:LinkButton ID="LinkButton1" Runat="server" CommandName="showorders" Text='<%# Container.DataItem("DefaultProductText") %>' ></asp:LinkButton>
      </td>
      <td align="left" width="10%">
      <asp:TextBox id="Quantity" runat="server" Columns="4" MaxLength="3" Text='<%# DataBinder.Eval(Container.DataItem, "DefaultQuantity") %>' width="40px" />
      </td>
      <td align="left" width="10%">
      <%# Container.DataItem("strMfree") %>
      </td>
      <td align="right" width="10%">
      <%# Container.DataItem("strSalesprice") %>
      </td>
      </tr>
      </table>
      <asp:Panel ID="products" Runat="server" Width="100%">
      <iframe id="iframe1" width="100%" src="prodlisting.aspx?id=<%# Container.DataItem("CompLinkID") %>"</iframe>
      </asp:Panel>
</ItemTemplate>
</asp:DataList>

//the page that is diplayed inside the IFRAME

Sub Page_Load(obj As Object, E As EventArgs)
    ...databinding code for the grid
End Sub

Sub DataGrid1_Update(obj as object, e as DataGridCommandEventArgs)
      If e.commandname="update" then
      dim objConn As New SqlConnection(ConfigurationSettings.AppSettings.Get("DbConn"))
      
      Dim intCompLinkID as Integer = Request.QueryString("id")
      
      Dim strProdNumber as String = CType(e.Item.Cells(0).Controls(1), Label).Text
      Dim strProdText as String = CType(e.Item.Cells(1).Controls(1), Label).Text
                        
      'Update statement
      Dim strUpdate as String = _
      "UPDATE tblCompLink SET DefaultProductText = @DefaultProductText, DefaultProductNumber = @DefaultProductNumber WHERE CompLinkID =" & intCompLinkID

      Dim myCommand as SqlCommand = new SqlCommand(strUpdate, objConn)
      myCommand.CommandType = CommandType.Text

      ' Add Parameters to the SQL query
      Dim parameterLevel1 as SqlParameter = _
                new SqlParameter("@DefaultProductNumber", SqlDbType.varchar, 20)
      parameterLevel1.Value = strProdNumber
      myCommand.Parameters.Add(parameterLevel1)

      Dim parameterLevel2 as SqlParameter = _
                new SqlParameter("@DefaultProductText", SqlDbType.varchar, 100)
      parameterLevel2.Value = strProdText
      myCommand.Parameters.Add(parameterLevel2)

      try
      objConn.Open()
      myCommand.ExecuteNonQuery()
      catch sqlerr as SQLException
      Throw sqlerr'Message.text="SQLError# =" & sqlerr.Number & ", SQL Msg=" & sqlerr.Message
      finally
      objConn.Close()
      end try
      End if
            
End sub

</script>
</head>
<body class="bodyspacer">
            <form id="Form1" method="post" runat="server">
                  <asp:literal id="output" runat="server" />
                  <asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" Width="100%"
                  OnUpdateCommand="DataGrid1_Update">
                  <Columns>
                        <asp:TemplateColumn HeaderText="Id">
                        <ItemTemplate>
                        <asp:Label ID="lblIT" Runat="server" Text='<%# Container.DataItem("strIT") %>' />
                        </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:TemplateColumn HeaderText="RBProdukt">
                        <ItemTemplate>
                        <asp:Label ID="lblTEXT" Runat="server" Text='<%# Container.DataItem("strTEXT") %>' />
                        </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:TemplateColumn HeaderText="Mfr">
                        <ItemTemplate>
                        <asp:Label ID="lblMFR" Runat="server" Text='<%# Container.DataItem("strMFR") %>' />
                        </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:TemplateColumn HeaderText="Pris">
                        <ItemTemplate>
                        <asp:Label ID="lblQty" Runat="server" Text='<%# Container.DataItem("strPrice") %>' />
                        </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:TemplateColumn>
                        <ItemTemplate>
                        <asp:ImageButton ID="btnUpdate" CommandName="Update" ImageAlign="AbsMiddle" ImageUrl="images/icon_plus.gif" Runat="server"  />
                        </ItemTemplate>
                        </asp:TemplateColumn>
                  </Columns>
                  </asp:DataGrid>
            </form>
      </body>
</html>

</CODE>
0
Comment
Question by:EspenP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
roverm earned 120 total points
ID: 9809234
Yes, it's because the grid is in an IFRAME.
The postback is fired on Form1 (or whatever you renamed it to). This could be the error.

If you only want to show/hide the datagrid the you could use a scrollable DIV.
The DIV will be rendered on the main page so that the postback will work ok:

<DIV id='scrolldiv' name='scrolldiv' class='scrolldiv' nowrap style='OVERFLOW-Y:auto; OVERFLOW-X:auto'>
    ...insert your code here
</DIV>

D'Mzz!
RoverM

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10277152
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: roverm {http:#9809234}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question