Hi Programmers
i have a formView inside updatepanel .
and i have two divs (one for success insert and the other for failed insertion) their styles display = none .
and i have two javascript functions tom call two divs with id and make their styles = block
i want to call these function after user click form view insert button inside the update panel
Note: the code works correctly without using update panel
here is the aspx code
<%@ Page Language="C#" MasterPageFile="MasterPage2.master" AutoEventWireup="true" CodeFile="schools1.aspx.cs" Inherits="Adminstration_schools1" Title="Untitled Page" %>
<%@ Register src="usercontrols/Print.ascx" tagname="Print" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<br />
<script type="text/javascript">
function ok()
{
document.getElementById("ok").style.display = "block";
}
function error()
{
document.getElementById("error").style.display = "block";
}
</script>
<div class="alert_success" id="ok" style="display:none">
<p>
<img src="images/icon_accept.png" alt="success" class="mid_align"/>
OK Inserted Sucessfully
</p>
</div>
<div class="alert_error" id="error" style="display:none">
<p>
<img src="images/icon_error.png" alt="delete" class="mid_align"/>
Error Record Not inserted
</p>
</div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="schoolId"
DataSourceID="schoolsDataSource1" DefaultMode="Insert"
oniteminserting="FormView1_ItemInserting" Width="98%" dir="rtl"
CellPadding="10" ForeColor="#333333" Caption="Add School"
CellSpacing="10" BorderStyle="Dashed"
oniteminserted="FormView1_ItemInserted" >
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditItemTemplate>
schoolId:
<asp:Label ID="schoolIdLabel1" runat="server" Text='<%# Eval("schoolId") %>' />
<br />
schname:
<asp:TextBox ID="schnameTextBox" runat="server" Text='<%# Bind("schname") %>' />
<br />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
tel:
<asp:TextBox ID="telTextBox" runat="server" Text='<%# Bind("tel") %>' />
<br />
scdate:
<asp:TextBox ID="scdateTextBox" runat="server" Text='<%# Bind("scdate") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Name:
<asp:TextBox ID="schnameTextBox" runat="server"
Text='<%# Bind("schname") %>' />
<br />
<br />
Address:
<asp:TextBox ID="addressTextBox" runat="server"
Text='<%# Bind("address") %>' />
<br />
<br />
tel:
<asp:TextBox ID="telTextBox" runat="server" Text='<%# Bind("tel") %>' />
<br />
<br />
Date:
<asp:TextBox ID="scdateTextBox" runat="server" Text='<%# Bind("scdate") %>'
ondatabinding="scdateTextBox_DataBinding" ReadOnly="True" />
<br />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" Font-Bold="True" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel"
Font-Bold="True" />
</InsertItemTemplate>
<ItemTemplate>
schoolId:
<asp:Label ID="schoolIdLabel" runat="server" Text='<%# Eval("schoolId") %>' />
<br />
schname:
<asp:Label ID="schnameLabel" runat="server" Text='<%# Bind("schname") %>' />
<br />
address:
<asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>' />
<br />
tel:
<asp:Label ID="telLabel" runat="server" Text='<%# Bind("tel") %>' />
<br />
scdate:
<asp:Label ID="scdateLabel" runat="server" Text='<%# Bind("scdate") %>' />
<br />
</ItemTemplate>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"
BorderColor="Red" BorderStyle="Solid" HorizontalAlign="Center" />
<InsertRowStyle HorizontalAlign="Right" BorderColor="#669900"
BorderStyle="Dashed" BorderWidth="1px" Font-Names="tahoma"
VerticalAlign="Middle" Wrap="True" />
<EditRowStyle BackColor="#2461BF" />
</asp:FormView>
<br />fhh
<br />
</ContentTemplate>
</asp:UpdatePanel>
<p>
</p>
<p>
</p>
<p>
<asp:SqlDataSource ID="schoolsDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:studentsdbConnectionString %>"
DeleteCommand="DELETE FROM [Schools] WHERE [schoolId] = @schoolId"
InsertCommand="INSERT INTO [Schools] ([schname], [address], [tel], [scdate]) VALUES (@schname, @address, @tel, @scdate)"
SelectCommand="SELECT * FROM [Schools]"
UpdateCommand="UPDATE [Schools] SET [schname] = @schname, [address] = @address, [tel] = @tel, [scdate] = @scdate WHERE [schoolId] = @schoolId" >
<DeleteParameters>
<asp:Parameter Name="schoolId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="schname" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="tel" Type="String" />
<asp:Parameter DbType="DateTime" Name="scdate" />
<asp:Parameter Name="schoolId" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="schoolId" Type="Int32" />
<asp:Parameter Name="schname" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="tel" Type="String" />
<asp:Parameter DbType="DateTime" Name="scdate" />
</InsertParameters>
</asp:SqlDataSource>
<br />
</p>
<p>
<div id="schools">
<asp:GridView ID="GridView1" runat="server" DataSourceID="schoolsDataSource1"
AutoGenerateColumns="False" DataKeyNames="schoolId" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="100%" AllowPaging="True"
AllowSorting="True" onselectedindexchanged="GridView1_SelectedIndexChanged">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center"
Font-Names="tahoma" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="schoolId" HeaderText="schoolId"
InsertVisible="False" ReadOnly="True" SortExpression="schoolId"
Visible="False" />
<asp:BoundField DataField="schname" HeaderText="name"
SortExpression="schname" />
<asp:BoundField DataField="address" HeaderText="address"
SortExpression="address" />
<asp:BoundField DataField="tel" HeaderText="tel" SortExpression="tel" />
<asp:TemplateField HeaderText="date" SortExpression="scdate">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("scdate") %>'
ondatabinding="scdateTextBox_DataBinding"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("scdate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate>
schoolId
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
HorizontalAlign="Center" Font-Names="tahoma" />
<EditRowStyle BackColor="#999999" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>
</p>
<uc1:Print ID="Print1" runat="server" />
<p>
</p>
<p>
<input id="Button1" type="button" value="طباعة" önclick="javascript:CallPrint('schools')" /> </p>
</asp:Content>
<asp:Content ID="Content3" runat="server"
contentplaceholderid="ContentPlaceHolder2">
<p>
add new schhol</p>
</asp:Content>
and this is the .CS Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Adminstration_schools1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
filldate();
}
private void filldate()
{
if (FormView1.CurrentMode == FormViewMode.Insert)
{
TextBox dateadded = FormView1.FindControl("scdateTextBox") as TextBox;
dateadded.Text = DateTime.Now.ToString();
}
}
protected void FormView1_DataBound(object sender, EventArgs e)
{
filldate();
}
protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{
foreach (DictionaryEntry entry in e.Values)
{
if (entry.Value.Equals(""))
{
e.Cancel = true;
ClientScript.RegisterStartupScript(GetType(), "hwa", "error();", true);
}
}
}
protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
if (e.AffectedRows > 0)
{
ClientScript.RegisterStartupScript(GetType(), "hwa", "ok();", true);
}
}
protected void scdateTextBox_DataBinding(object sender, EventArgs e)
{
TextBox scdateTextBox = (TextBox)sender;
scdateTextBox.Text = DateTime.Now.ToString();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}