Click here to Skip to main content
12,302,514 members (64,927 online)
Rate this:
 
Please Sign up or sign in to vote.
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") %>' />

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)
    {
       // FormView1.ChangeMode(FormViewMode.Insert);
       // filldate();

        foreach (DictionaryEntry entry in e.Values)
        {
            if (entry.Value.Equals(""))
            {
                // Use the Cancel property to cancel the 
                // insert operation.
                e.Cancel = true;
 
                ClientScript.RegisterStartupScript(GetType(), "hwa", "error();", true);
 
            }
        }
    }
 
    protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        //FormView1.ChangeMode(FormViewMode.Insert);
        //filldate();

        if (e.AffectedRows > 0)
        {
 
            ClientScript.RegisterStartupScript(GetType(), "hwa", "ok();", true);
        }
 

    }
    protected void scdateTextBox_DataBinding(object sender, EventArgs e)
    {
        TextBox scdateTextBox = (TextBox)sender;
 
        // Retrieve and assign default number
        scdateTextBox.Text = DateTime.Now.ToString();
 
        
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
 
    }
}
Posted 29-Aug-12 23:55pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hello

you had written code for adding javascript while post back, your code as below

if (e.AffectedRows > 0)
        {
 
            ClientScript.RegisterStartupScript(GetType(), "hwa", "ok();", true);
        }


Update your code with below code


if (e.AffectedRows > 0)
        {
              ScriptManager.RegisterStartupScript(this, this.GetType(), "hwa", "ok();", true);
           
        }


Regards
Gaurav Dhol
  Permalink  
Comments
progahmed 30-Aug-12 7:14am
   
ohhhhhhh, You are right

It is working successfully .

Thank you Gaurav Dhol Very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160530.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100