Solved

Page unloads when I display an alert....URRGENT!...

Posted on 2009-05-14
7
822 Views
Last Modified: 2012-05-07
I have  a datagrid with 7 columns and button below it which when clicked displays a panel
with 7 textboxes, which need to be filled in. The panel has 3 buttons ....at the bottom, baddsave, beditsave and cancel. the 2nd column of teh grid is a link which whne clicked
dispalys the panle with the textboxes populated with the column value sin the grid an dteh user is allowed to edit the values except the 1st textboxes which conatins the value of the 1st column of teh grid which is a primary key...when the baddsave is clicked, I'm testing if there are any duplicate records, if so, I'm displaying a popup message to the user saying duplicate records.similarly when a record is added or updated, I'm displaying a popup message ....but when it displays any of these messages, the page becomes blank (may be it's getting unloaded)a nd when I click "ok" on the popup it comes back to the page.

U might suggest me to send  amessage from the store dprocedure and display it, but I cannot do that, as database codedoes not allow me .
could anyone pleas ehelp me resolve this.....it's extremely urgent...NEED IT BY TOMORROW MORNING...PLEASE DON'T NEGLECT IT!
Thanks a million in advance!
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductTypes.aspx.cs" Inherits="wbsser.ProductTypes" %>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
    
<head id="Head1" runat="server">
    <link href="../Styles/master.css" rel="stylesheet" type="text/css" />
    <title>Product Types</title>
    
</head>
<body>
    <form id="form1" runat="server">
        <table width="900px" cellpadding="0" cellspacing="0" border="0">
        
		<tr>			
			<td align="right" valign="top"  width="20%">
			  <span class="button" style="BACKGROUND-COLOR: transparent"><input runat="server" id="bClose" type="button" value="Close" onclick='window.close();' style="font-weight:bold;" /></span>
			</td>
		</tr>
		
            <tr>
                <td align="center">
                    <!-- form content here -->
                    <!-- form content here -->
                    <!-- form content here -->
                    <fieldset>
                    <table width="98%" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td align="center" class="largeHeader">
                                Product Types
                            </td>
                        </tr>
                        <tr>
                      <%-- 2009June   Amukta Start--%>
                            <td align="center">
                                <asp:DataGrid runat=server ID=dgProdType HeaderStyle-CssClass=dgHeader ItemStyle-CssClass=dgItem AlternatingItemStyle-CssClass=dgItemAlternate Width=100% DataKeyField="PROD_ID"  AllowSorting="True" AutoGenerateColumns="False" 
                                  OnSortCommand="dgProdType_SortCommand" OnSelectedIndexChanged="dgProdType_SelectedIndexChanged" >
                                    <AlternatingItemStyle CssClass="dgItemAlternate" />
                                    <ItemStyle CssClass="dgItem" />
                                    <HeaderStyle CssClass="dgHeader" />
                                    <PagerStyle NextPageText="&amp;lt;Next&amp;gt;" PrevPageText="&amp;lt;Prev&amp;gt;" HorizontalAlign="Right"></PagerStyle>								                                   
                                    <Columns>
                                       <asp:BoundColumn DataField="PROD_ID" HeaderText="Product Id" SortExpression="PROD_ID" ItemStyle-Width="80px"></asp:BoundColumn>
                                       <asp:TemplateColumn HeaderText="Product Desc" SortExpression="PROD_DESC">
                                            <ItemTemplate>                                              
                                              <asp:LinkButton runat="server" CssClass=href id="lnkProdDesc" CommandName="Select" Text='<%# DataBinder.Eval(Container.DataItem,"PROD_DESC")%>'/>
                                            </ItemTemplate>
                                        </asp:TemplateColumn>                              
                                        <asp:BoundColumn HeaderText="Auth to Req" DataField="AUTH_TO_REQ"></asp:BoundColumn>
                                        <asp:BoundColumn HeaderText="Suppress Prd" DataField="SUPPRESS_PRD"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="REVENUE" HeaderText="Revenue"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="SCRIPT" HeaderText="Script"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="PRIORITY" HeaderText="Priority"></asp:BoundColumn>
                                    </Columns> 
                                </asp:DataGrid>
                            </td>
                                                       
                        </tr>
                        <tr>
                            <td align=right>
                                <span class="button" style="background-color: transparent">
                                <asp:Button runat=server ID=buttAddNewItem Text="Add New Product Type" OnClick="buttAddNewItem_Click" />
                                </span>
                            </td>
                         </tr>
                                                
                        </table>
                       </fieldset>
                                      
                       <br />
                       
                       <table width="100%" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td align=center>
                                <asp:Panel ID="pEdit" runat=server Visible=false>
                                <table width=100% style="BORDER-RIGHT: gray 1px solid; BORDER-TOP: gray 1px solid; BORDER-LEFT: gray 1px solid; BORDER-BOTTOM: gray 1px solid"
				                       border="0">
				                      <tr>
					                      <td class="dgheader"  colSpan="2" height="25"><font size="larger">Product Types - Edit</font>
					                      </td>
				                      </tr>
				                      <tr>
				                         <td colspan="2">
				                           <table class="tr1normal" width=100% cellspacing="0" cellpadding="0">
				                             <tr>
								                        <td align="right"><asp:Label runat="server" ID="lProdId" CssClass="label" Text="Product Id:"></asp:Label></td>
								                        <td><asp:textbox id="tProdId" Runat="server" CssClass="textbox" text="" width="25px" maxlength="3"></asp:textbox></td>
								                        <td align="right">&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label runat=server ID="lProdDesc" CssClass="label" Text="*Product Description:"></asp:Label></td>
									                    <td><asp:textbox id="tProdDesc" Runat="server" CssClass="textbox" text="" width="120px" maxlength="50"></asp:textbox></td></tr>
									                  
									                    <tr>
									                    <td align="right"><asp:Label runat=server id="lAuthReq" CssClass="label" Text="*Auth To Req:"></asp:Label></td>
									                    <td><asp:textbox id="tAuthReq" Runat="server" CssClass="textbox" text="" width="120px" maxlength="50"></asp:textbox></td>			                           
									                    <td align="right">&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="lSuppressPrd" runat="server" CssClass="label" Text="Suppress Prd:"></asp:Label>
								                        <td><asp:textbox id="tSuppressPrd" Runat="server" CssClass="textbox" text="" width="25px" maxlength="3"></asp:textbox><td>   								                        
									                     
							                   </tr>
							                  <tr>
 
								                        <td align="right"><asp:Label id="lRevenue" runat="server" CssClass="label" text="*Revenue:"></asp:Label></td>
									                    <td><asp:textbox id="tRevenue" Runat="server" CssClass="textbox" text="" width="120px" maxlength="50"></asp:textbox></td>
									                    <td align="right">&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label id="lScript" runat="server" CssClass="label" Text="*Script:"></asp:Label></td>
									                    <td><asp:textbox id="tScript" Runat="server" CssClass="textbox" text="" width="300px" maxlength="2000"></asp:textbox></td>		                     
									                     
									                        
							                   </tr>
							                   <tr>
								                        <td align="right"><asp:Label id="lPriority" runat="server" CssClass="label" Text="*Priority:"></asp:Label></td>
								                        <td><asp:textbox id="tPriority" Runat="server" CssClass="textbox" text="" width="25px" maxlength="3"></asp:textbox></td>					                        						                           
									             
							                    </tr>
				                           </table>
				                         </td>
				                      
				                      
				                      </tr> 
				                       <tr>
					                <td><font class="errorText">* denotes required field</font></td>					               
					                <td align="center">
					                    <span class="button">
					                    <asp:button id="bAddSave" Runat="server" Text="Save" OnClick="bAddSave_Click"></asp:button>
                                        </span>&nbsp;
                                        <span class="button" style="background-color: transparent">
					                    <asp:button id="bEditSave" Runat="server" Text="Save" OnClick="bEditSave_Click"></asp:button>
					                    </span>&nbsp;
					                    <span class="button" style="background-color: transparent">
					                     <asp:button id="bCancel" Runat="server" Text="Cancel" OnClick="bCancel_Click"></asp:button>
					                    </span>
					
					                </td>
				               </tr>
				                     
				                </table>
				                 <script language="javascript" type="text/javascript">
 
                                  function validateFieldsonAdd() 
                                  {
                                   window.event.returnValue = false;
                                   if (trim(form1.tProdId.value)=="" ) 
                                   {
                                    alert("Product Id is required!");
                                    form1.tProdId.focus();
                                    return;
                                   }
                                   if (!(trim(form1.tProdId.value))=="")
                                    {
                                      if (isNaN(trim(form1.tProdId.value))) 
                                       {
                                        alert("Product has to be a numeric value!");
                                         form1.tProdId.focus();
                                         return;
                                       }
                                    }
               
                                  if (trim(form1.tProdDesc.value) == "") 
                                  {
                                    alert("Product Description is required!");
                                    form1.tProdDesc.focus();
                                    return;
                                  }
                                 if (trim(form1.tAuthReq.value) == "") 
                                 {
                                    alert("Auth to Req is required!");
                                    form1.tAuthReq.focus();
                                    return;
                                 }                
 
                                if (trim(form1.tSuppressPrd.value)=="")
                                {
                                   alert("Suppress Prd is required!");
                                   form1.tSuppressPrd.focus();
                                   return;
                                }
                                  if (!(trim(form1.tSuppressPrd.value))=="")
                                 {
                                   if (isNaN(trim(form1.tSuppressPrd.value))) 
                                  {
                                     alert("Suppress Prd must be a numeric value!");
                                     form1.tSuppressPrd.focus();
                                     return;
                                   }
                                 }
                
                                if (trim(form1.tRevenue.value) == "") 
                               {
                                  alert("Revenue is required!");
                                  form1.tRevenue.focus();
                                  return;
                               }
 
                              if (trim(form1.tPriority.value) == "") 
                              {
                                 alert("Priority is required!");
                                 form1.tPriority.focus();
                                 return;
                              }
                              if (!(trim(form1.tPriority.value)) == "") 
                              {
                               if(isNaN(trim(form1.tPriority.value)))
                               {
                                 alert("Priority has to be a numeric value!");
                                 form1.tPriority.focus();
                                 return;
                               
                               }
                              }
                              if (!window.confirm("Insert this record?")) return;
                
                              window.event.returnValue = true;
 
                          }            
                
               
          
 
                          function trim(string){return string.replace(/(^\s*)|(\s*$)/g, "");}		
 
                          function validateFieldsonEdit() 
                         {
                              window.event.returnValue = false;
                              if (!trim(form1.tProdId.value)=="")
                              {
                                if (isNaN(trim(form1.tProdId.value))) 
                                {
                                 alert("Product must be a numeric value!");
                                 form1.tProdId.focus();
                                 return;
                                }
                             }
                             if (trim(form1.tProdDesc.value) == "") 
                             {
                               alert("Product Description is required!");
                               form1.tProdDesc.focus();
                               return;
                             }
                             if (trim(form1.tAuthReq.value) == "") 
                             {
                               alert("Auth to Req is required!");
                               form1.tAuthReq.focus();
                               return;
                             }                
 
                            if (trim(form1.tSuppressPrd.value)=="" ) 
                            {
                              alert("Suppress Prd is required!");
                              form1.tSuppressPrd.focus();
                              return;
                            }
                             if (!trim(form1.tSuppressPrd.value)=="")
                                 {
                                   if (isNaN(trim(form1.tSuppressPrd.value))) 
                                  {
                                     alert("Suppress Prd must be a numeric value!");
                                     form1.tSuppressPrd.focus();
                                     return;
                                   }
                                 }
                
                           if (trim(form1.tRevenue.value) == "") 
                           {
                             alert("Revenue is required!");
                             form1.tRevenue.focus();
                             return;
                           }
 
                          if (trim(form1.tPriority.value) == "" ) 
                          {
                            alert("Priority is required!");
                            form1.tPriority.focus();
                            return;
                          }
                          if (!trim(form1.tPriority.value)=="")
                                 {
                                   if (isNaN(trim(form1.tPriority.value))) 
                                  {
                                     alert("Priority must be a numeric value!");
                                     form1.tPriority.focus();
                                     return;
                                   }
                                 }
                                 if (!window.confirm("Update this record?")) return;
                
                          window.event.returnValue = true;
 
                        }    
 
                      </script>
                      
                    </asp:Panel>
                      
                   
                   </td>   
                  </tr>
                 </table>
              
    </form>
  </body>
</html>       
     -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
namespace wbsser
{
    public partial class ProductTypes : System.Web.UI.Page
    {
 
        private const string mStoredProcedureName = "sp";
        public ProductTypes()
        {
        }
        ~ProductTypes()
        {
            this.Database = null;
        }
        private wbsser.Database _DataBase;
        private wbsser.Database Database
        {
            get
            {
                if (_DataBase == null)
                {
                    _DataBase = new wbsser.Database();
                }
                return (_DataBase);
            }
            set
            {
                if (!(_DataBase == null))
                {
                    _DataBase.Dispose();
                }
                _DataBase = value;
            }
        }
 
 
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!Page.IsPostBack)
            {
                displayInfo(null);
                bAddSave.Attributes.Add("onClick", "validateFieldsonAdd();");
                bEditSave.Attributes.Add("onClick", "validateFieldsonEdit();");
            }
           
               
            
        }
 
        private void displayInfo(string pSortField)
        {
            DataSet mds = null;
            mds=new DataSet();
 
            try
            {
                Database.Param("@Action", SqlDbType.VarChar, "select");
 
                SqlDataAdapter mda = Database.ExecuteSPReturnDS(mStoredProcedureName, true);
                mda.Fill(mds);
 
                if (pSortField != null)
                {
                    mds.Tables[0].DefaultView.Sort = pSortField + " " + ViewState["SortDirection"];
 
                }
                else
                {
                    ViewState["SortField"] = "PROD_DESC";
                    ViewState["SortDirection"] = "ASC";
                }
              
                dgProdType.DataSource = mds.Tables[0].DefaultView;
                dgProdType.DataBind();
 
            }
 
            catch (Exception ex)
            {
                throw ex;
 
            }
            finally
            {
                mds = null;
                Database = null;
 
            }
        }
        protected void dgProdType_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
        {
            if (e.SortExpression.ToUpper() == ViewState["SortField"].ToString())
            {
                if (ViewState["SortDirection"].ToString() == "ASC")
                    ViewState["SortDirection"] = "DESC";
                else
                    ViewState["SortDirection"] = "ASC";
            }
            else
            {
                ViewState["SortField"] = e.SortExpression.ToUpper();
                if (ViewState["SortDirection"].ToString() == "ASC")
                    ViewState["SortDirection"] = "DESC";
                else
                    ViewState["SortDirection"] = "ASC";
            }
          
            displayInfo(e.SortExpression);
        }
       
 
        protected void buttAddNewItem_Click(object sender, EventArgs e)
        {
           
            tProdId.ReadOnly = false;
            tProdId.Text = "";
            tProdDesc.Text = "";
            tAuthReq.Text = "";
            tSuppressPrd.Text = "";
            tRevenue.Text = "";
            tScript.Text = "";
            tPriority.Text = "";
            pEdit.Visible = true;
            bEditSave.Visible=false;
            bAddSave.Visible = true;
        
 
        }
 
       
        protected void bAddSave_Click(object sender, EventArgs e)
        {
            int iReturn_Value = 0;
            bool retDup;
 
            try
            {
                retDup = checkDuplicates(Convert.ToInt32(tProdId.Text));
                if (retDup == true)
                {
                   ShowMessage(this.Page,"A Record with this Product Id already exists! Please enter a record with different Product Id");
                   pEdit.Visible = true; 
                   
                }
                else
                {                  
                    Database.Param("@Action", SqlDbType.VarChar, "insert", 25);
                    Database.Param("@PROD_ID", SqlDbType.Int, tProdId.Text, 3);
                    Database.Param("@PROD_DESC", SqlDbType.VarChar, tProdDesc.Text, 50);
                    Database.Param("@AUTH_TO_REQ", SqlDbType.VarChar, tAuthReq.Text, 50);
                    Database.Param("@SUPPRESS_PRD", SqlDbType.Int, tSuppressPrd.Text, 3);
                    if (tRevenue.Text == "" || String.IsNullOrEmpty(tRevenue.Text))
                    {
                        Database.Param("@REVENUE", SqlDbType.VarChar, DBNull.Value);
                    }
                    else
                    {
                        Database.Param("@REVENUE", SqlDbType.VarChar, tRevenue.Text, 50);
                    }
 
                    if (tScript.Text == "" || String.IsNullOrEmpty(tScript.Text))
                    {
                        Database.Param("@SCRIPT", SqlDbType.VarChar, DBNull.Value);
                    }
                    else
                    {
                        Database.Param("@SCRIPT", SqlDbType.VarChar, tScript.Text, 2000);
                    }
                    Database.Param("@PRIORITY", SqlDbType.Int, tPriority.Text, 3);
                    Database.ExecuteStoreProcedure(mStoredProcedureName, true, false, CommandBehavior.CloseConnection, iReturn_Value);
                 
                    if (iReturn_Value >= 0)
                        Common.ShowMessage(this.Page, "New Product Type Added Successfully!");
                     displayInfo(ViewState["SortField"].ToString());
                     pEdit.Visible = false; 
                }
            }
           
            catch (Exception ex)
            {
 
                throw ex;
            }
            finally
            {
                Database = null;
            }
           
        }
  public static void ShowMessage(System.Web.UI.Page Page, string Message) {
        System.Text.StringBuilder sScript = new System.Text.StringBuilder();        
       
        //  ---------------------------------------------------------------------------------
        //  Display as JavaScript alert
        //  ---------------------------------------------------------------------------------
        sScript.Append((" <Script Language=\'javascript\'>" ));
        sScript.Append((" alert(\'" 
                        + (Message + ("\')"))));
       
        sScript.Append(" </Script>");
        if (!Page.ClientScript.IsStartupScriptRegistered("fncAlertMSG")) {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "fncAlertMSG", sScript.ToString());
        }
        sScript = null;
       
    }
        protected void bEditSave_Click(object sender, EventArgs e)
        {
            int iReturn_Value=0;
            try
            {
 
                Database.Param("@Action", SqlDbType.VarChar, "update", 25);
                Database.Param("@PROD_ID", SqlDbType.Int, tProdId.Text, 3);
                Database.Param("@PROD_DESC", SqlDbType.VarChar, tProdDesc.Text, 50);
                Database.Param("@AUTH_TO_REQ", SqlDbType.VarChar, tAuthReq.Text,50);
                Database.Param("@SUPPRESS_PRD", SqlDbType.Int, tSuppressPrd.Text,3);
                Database.Param("@REVENUE", SqlDbType.VarChar, tRevenue.Text, 50);
                
               
                if (tScript.Text == "" || String.IsNullOrEmpty(tScript.Text))
                {
                    Database.Param("@SCRIPT", SqlDbType.VarChar, DBNull.Value);
                }
                else
                {
                    Database.Param("@SCRIPT", SqlDbType.VarChar, tScript.Text, 2000);
                }
                Database.Param("@PRIORITY", SqlDbType.Int, tPriority.Text,3);
                Database.ExecuteStoreProcedure(mStoredProcedureName, true, false, CommandBehavior.CloseConnection, iReturn_Value);
                if (iReturn_Value >= 0)
                   showMessage(this.Page, "Product Type Updated Successfully!");
 
                displayInfo(null);
                pEdit.Visible = false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
 
                Database = null;
            }
 
 
 
        }
 
        protected void dgProdType_SelectedIndexChanged(Object sender, EventArgs e)
        {
            try
            {              
 
                tProdId.ReadOnly = true;
                tProdId.Text = dgProdType.SelectedItem.Cells[0].Text.ToString();
                tProdDesc.Text = ((LinkButton)dgProdType.SelectedItem.Cells[1].FindControl("lnkProdDesc")).Text.ToString();                       
                tAuthReq.Text = dgProdType.SelectedItem.Cells[2].Text.ToString();               
                tSuppressPrd.Text = dgProdType.SelectedItem.Cells[3].Text.ToString();                         
                tRevenue.Text = dgProdType.SelectedItem.Cells[4].Text.ToString();
                
               
                if (tScript.Text == "" || String.IsNullOrEmpty(tScript.Text))
                {
                    tScript.Text = "";
                }
                else
                {
                    tScript.Text = dgProdType.SelectedItem.Cells[5].Text.ToString();
                }
                tPriority.Text = dgProdType.SelectedItem.Cells[6].Text.ToString();
 
                pEdit.Visible = true;
                bEditSave.Visible = true;
                bAddSave.Visible = false;
 
                displayInfo(ViewState["SortField"].ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Database = null;
            }
 
        }
 
        protected void bCancel_Click(object sender, EventArgs e)
        {
            pEdit.Visible = false;
            displayInfo(null);
        }
       
 
        protected bool checkDuplicates(int pDupProdId)
        {
           
            DataSet mds = null;
            mds = new DataSet();
          
            try
            {
 
                Database.Param("@Action", SqlDbType.VarChar, "selectdup", 25);
                Database.Param("@PROD_ID", SqlDbType.Int,pDupProdId, 3);
 
                SqlDataAdapter mda = Database.ExecuteSPReturnDS(mStoredProcedureName, true);
                mda.Fill(mds);
                if (mds.Tables[0].Rows.Count > 0)
                {
                   return true;
                }
                else
                {
                   return false;
                }
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                mds = null;
                Database = null;
            }
        }
       
 
 
    }
 
}

Open in new window

0
Comment
Question by:amukta
[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
  • 5
  • 2
7 Comments
 

Author Comment

by:amukta
ID: 24392449
PLusing System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace wbsser
{
    public partial class ProductTypes : System.Web.UI.Page
    {

        private const string mStoredProcedureName = "sp";
        public ProductTypes()
        {
        }
        ~ProductTypes()
        {
            this.Database = null;
        }
        private wbsser.Database _DataBase;
        private wbsser.Database Database
        {
            get
            {
                if (_DataBase == null)
                {
                    _DataBase = new wbsser.Database();
                }
                return (_DataBase);
            }
            set
            {
                if (!(_DataBase == null))
                {
                    _DataBase.Dispose();
                }
                _DataBase = value;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!Page.IsPostBack)
            {
                displayInfo(null);
                bAddSave.Attributes.Add("onClick", "validateFieldsonAdd();");
                bEditSave.Attributes.Add("onClick", "validateFieldsonEdit();");
            }
           
               
           
        }

        private void displayInfo(string pSortField)
        {
            DataSet mds = null;
            mds=new DataSet();

            try
            {
                Database.Param("@Action", SqlDbType.VarChar, "select");

                SqlDataAdapter mda = Database.ExecuteSPReturnDS(mStoredProcedureName, true);
                mda.Fill(mds);

                if (pSortField != null)
                {
                    mds.Tables[0].DefaultView.Sort = pSortField + " " + ViewState["SortDirection"];

                }
                else
                {
                    ViewState["SortField"] = "PROD_DESC";
                    ViewState["SortDirection"] = "ASC";
                }
             
                dgProdType.DataSource = mds.Tables[0].DefaultView;
                dgProdType.DataBind();

            }

            catch (Exception ex)
            {
                throw ex;

            }
            finally
            {
                mds = null;
                Database = null;

            }
        }
        protected void dgProdType_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
        {
            if (e.SortExpression.ToUpper() == ViewState["SortField"].ToString())
            {
                if (ViewState["SortDirection"].ToString() == "ASC")
                    ViewState["SortDirection"] = "DESC";
                else
                    ViewState["SortDirection"] = "ASC";
            }
            else
            {
                ViewState["SortField"] = e.SortExpression.ToUpper();
                if (ViewState["SortDirection"].ToString() == "ASC")
                    ViewState["SortDirection"] = "DESC";
                else
                    ViewState["SortDirection"] = "ASC";
            }
         
            displayInfo(e.SortExpression);
        }
       

        protected void buttAddNewItem_Click(object sender, EventArgs e)
        {
           
            tProdId.ReadOnly = false;
            tProdId.Text = "";
            tProdDesc.Text = "";
            tAuthReq.Text = "";
            tSuppressPrd.Text = "";
            tRevenue.Text = "";
            tScript.Text = "";
            tPriority.Text = "";
            pEdit.Visible = true;
            bEditSave.Visible=false;
            bAddSave.Visible = true;
       

        }

       
        protected void bAddSave_Click(object sender, EventArgs e)
        {
            int iReturn_Value = 0;
            bool retDup;

            try
            {
                retDup = checkDuplicates(Convert.ToInt32(tProdId.Text));
                if (retDup == true)
                {
                   ShowMessage(this.Page,"A Record with this Product Id already exists! Please enter a record with different Product Id");
                   pEdit.Visible = true;
                   
                }
                else
                {                  
                    Database.Param("@Action", SqlDbType.VarChar, "insert", 25);
                    Database.Param("@PROD_ID", SqlDbType.Int, tProdId.Text, 3);
                    Database.Param("@PROD_DESC", SqlDbType.VarChar, tProdDesc.Text, 50);
                    Database.Param("@AUTH_TO_REQ", SqlDbType.VarChar, tAuthReq.Text, 50);
                    Database.Param("@SUPPRESS_PRD", SqlDbType.Int, tSuppressPrd.Text, 3);
                    if (tRevenue.Text == "" || String.IsNullOrEmpty(tRevenue.Text))
                    {
                        Database.Param("@REVENUE", SqlDbType.VarChar, DBNull.Value);
                    }
                    else
                    {
                        Database.Param("@REVENUE", SqlDbType.VarChar, tRevenue.Text, 50);
                    }

                    if (tScript.Text == "" || String.IsNullOrEmpty(tScript.Text))
                    {
                        Database.Param("@SCRIPT", SqlDbType.VarChar, DBNull.Value);
                    }
                    else
                    {
                        Database.Param("@SCRIPT", SqlDbType.VarChar, tScript.Text, 2000);
                    }
                    Database.Param("@PRIORITY", SqlDbType.Int, tPriority.Text, 3);
                    Database.ExecuteStoreProcedure(mStoredProcedureName, true, false, CommandBehavior.CloseConnection, iReturn_Value);
                 
                    if (iReturn_Value >= 0)
                        Common.ShowMessage(this.Page, "New Product Type Added Successfully!");
                     displayInfo(ViewState["SortField"].ToString());
                     pEdit.Visible = false;
                }
            }
           
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                Database = null;
            }
           
        }
  public static void ShowMessage(System.Web.UI.Page Page, string Message) {
        System.Text.StringBuilder sScript = new System.Text.StringBuilder();        
       
        //  ---------------------------------------------------------------------------------
        //  Display as JavaScript alert
        //  ---------------------------------------------------------------------------------
        sScript.Append((" <Script Language=\'javascript\'>" ));
        sScript.Append((" alert(\'"
                        + (Message + ("\')"))));
       
        sScript.Append(" </Script>");
        if (!Page.ClientScript.IsStartupScriptRegistered("fncAlertMSG")) {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "fncAlertMSG", sScript.ToString());
        }
        sScript = null;
       
    }
        protected void bEditSave_Click(object sender, EventArgs e)
        {
            int iReturn_Value=0;
            try
            {

                Database.Param("@Action", SqlDbType.VarChar, "update", 25);
                Database.Param("@PROD_ID", SqlDbType.Int, tProdId.Text, 3);
                Database.Param("@PROD_DESC", SqlDbType.VarChar, tProdDesc.Text, 50);
                Database.Param("@AUTH_TO_REQ", SqlDbType.VarChar, tAuthReq.Text,50);
                Database.Param("@SUPPRESS_PRD", SqlDbType.Int, tSuppressPrd.Text,3);
                Database.Param("@REVENUE", SqlDbType.VarChar, tRevenue.Text, 50);
               
               
                if (tScript.Text == "" || String.IsNullOrEmpty(tScript.Text))
                {
                    Database.Param("@SCRIPT", SqlDbType.VarChar, DBNull.Value);
                }
                else
                {
                    Database.Param("@SCRIPT", SqlDbType.VarChar, tScript.Text, 2000);
                }
                Database.Param("@PRIORITY", SqlDbType.Int, tPriority.Text,3);
                Database.ExecuteStoreProcedure(mStoredProcedureName, true, false, CommandBehavior.CloseConnection, iReturn_Value);
                if (iReturn_Value >= 0)
                   showMessage(this.Page, "Product Type Updated Successfully!");

                displayInfo(null);
                pEdit.Visible = false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                Database = null;
            }



        }

        protected void dgProdType_SelectedIndexChanged(Object sender, EventArgs e)
        {
            try
            {              

                tProdId.ReadOnly = true;
                tProdId.Text = dgProdType.SelectedItem.Cells[0].Text.ToString();
                tProdDesc.Text = ((LinkButton)dgProdType.SelectedItem.Cells[1].FindControl("lnkProdDesc")).Text.ToString();                      
                tAuthReq.Text = dgProdType.SelectedItem.Cells[2].Text.ToString();              
                tSuppressPrd.Text = dgProdType.SelectedItem.Cells[3].Text.ToString();                        
                tRevenue.Text = dgProdType.SelectedItem.Cells[4].Text.ToString();
               
               
                if (tScript.Text == "" || String.IsNullOrEmpty(tScript.Text))
                {
                    tScript.Text = "";
                }
                else
                {
                    tScript.Text = dgProdType.SelectedItem.Cells[5].Text.ToString();
                }
                tPriority.Text = dgProdType.SelectedItem.Cells[6].Text.ToString();

                pEdit.Visible = true;
                bEditSave.Visible = true;
                bAddSave.Visible = false;

                displayInfo(ViewState["SortField"].ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Database = null;
            }

        }

        protected void bCancel_Click(object sender, EventArgs e)
        {
            pEdit.Visible = false;
            displayInfo(null);
        }
       

        protected bool checkDuplicates(int pDupProdId)
        {
           
            DataSet mds = null;
            mds = new DataSet();
         
            try
            {

                Database.Param("@Action", SqlDbType.VarChar, "selectdup", 25);
                Database.Param("@PROD_ID", SqlDbType.Int,pDupProdId, 3);

                SqlDataAdapter mda = Database.ExecuteSPReturnDS(mStoredProcedureName, true);
                mda.Fill(mds);
                if (mds.Tables[0].Rows.Count > 0)
                {
                   return true;
                }
                else
                {
                   return false;
                }
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                mds = null;
                Database = null;
            }
        }
       


    }

}
0
 

Author Comment

by:amukta
ID: 24392484
I cannot use AJAX.
0
 
LVL 4

Accepted Solution

by:
baiju_nagori earned 500 total points
ID: 24395088
Hi,

First option is to use a literal control and just assign the javascript to the text property of literal control. Do not use RegisterStartupScript.

If that doesnt work, then second option is to use Jquery's document ready function with above method.

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:amukta
ID: 24395154
Hi!

I cannot change teh function as i don't have access.
Could you please let e know what jquery is?
Do u have any logic for that?

Thanks,
0
 
LVL 4

Expert Comment

by:baiju_nagori
ID: 24395298
This is the logic of jQuery. You will need to download this file
http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js
and reference it in your HTML page.

Now this wont be of much use if you cannot change ShowMessage function.
Your problem is that alert function is blocking page load as it is registered as startup script (execute as soon as it is available on the page). This can be solved by jQuery, which will wait till entire page is loaded.

Just put following code in a literal control or registerstartupscript and add reference to jQuery file and your problem will be solved,

Baiju
<script type=text/javascript">
$(document).ready(function() {
    alert('Operation Completed!');;
});
</script>

Open in new window

0
 

Author Comment

by:amukta
ID: 24716635
Hi!

I just used a lable to display the message...I had gone on vacation, so didn't access this site....
I tried it and it does not work.

Can I get any other solution for it.
0
 

Author Comment

by:amukta
ID: 24716645
Sorry!
I cannot use jquery in my project.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

739 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