Hello.
I have a page where I have an online form. The messages sudmitted through this online form is stored in the Kentico database, and then displayed using the "RepeaterWithCustomQuery" web part. There is also a delete button that allows for the visitors to delete a message.
For the repeater, I wrote the transformation myself.
The page build up looks like this in design view in the online portal:
I have a custom query:
USE [Kentico82]
SELECT [LeaveAMessageID]
,[FormInserted]
,[TextBoxControl]
,[TextAreaControl]
FROM [dbo].[Form_IrisInformationSystem_LeaveAMessage]
order by [FormInserted] desc;
And i have my own homecooked transformation to go with it:
<%@ Import Namespace="System.Windows.Forms" %>
<%@ Import Namespace="System.Web.UI" %>
<div id="messages">
<table id="t01">
<thead>
<tr>
<th id="date">ID</th>
<th id="date">Date</th>
<th id="name">Name</th>
<th id="message">Message</th>
<th id="delete">Delete</th>
</tr>
</thead>
<tbody>
<tr>
<asp:HiddenField ID="idfield" runat="server" value='<%# GetNotEmpty("LeaveAMessageID") %>' />
<td id="idfield1"><%# GetNotEmpty("LeaveAMessageID") %></td>
<td id="datefield"><%# GetNotEmpty("FormInserted") %></td>
<td id="namefield"><%# GetNotEmpty("TextBoxControl") %></td>
<td id="messagefield"><%# GetNotEmpty("TextAreaControl") %></td>
<td id="deletebutton"><asp:Button id="Button1" Text="Delete Message" onclick="Button1_Click"
runat="server"> </asp:Button></td>
</tr>
</tbody>
</table>
</div>
<script runat="server">
void Button1_Click(object sender, EventArgs e) {
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Hello');", true);
try
{
var msgID = idfield.Value;//Request["idfield"];
//ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert(" + msgID +");", true);
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("myconnectionstringhere");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "DELETE FROM Form_IrisInformationSystem_LeaveAMessage WHERE LeaveAMessageID ="+msgID;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('An error occurred.');", true);
}
finally
{
// Response.Redirect(Request.RawUrl);
Response.Redirect("/Notes.aspx");
//Response.Write("<h1>Note deleted</h1>");
}
}
</script>
Now, this actually works great! I can submit a message, and see that it does appear both on the live site and in the database using SQL management studio. I can also see that is i press the dele button, the message disappears, both on the live site and on the database.
However, it only works when i display the page in preview mode. On the live site, I can still submit a message, but it does not show up on the live site even though I can see that it does appear in the database. The same goes for deleting, the message disappears from the database but remains on the live page.
It must have something to do with the repeater not refreshing the data, but I cannot for the life of me figure out why, especially since it works fine in preview mode.
Any suggestions?
Thanks in advance.