locked
No buttons working on webform after deployment to azure RRS feed

  • Question

  • User1317037654 posted

    Hello,

    I have a asp.net website, when I publish locally with local SQLexpress  it works. When I publish locally but connecting to azure Sql database it works. But when I publish it to my Azure App Service, login page etc works, but on one webform not buttons are working. I debugged by attaching debugger to AppService, th ebuttons are firing the event and all code is running fine but the webpage does not update with right data. For example for one button, I search a product reference from db and display the product name and prices on the web form. But When  debug, th ecode is working fine, its getting the product name right, but the info is not being posted on the webform. It seems the form is constantly being reset to empty page.

    Thanks,

    Thursday, August 10, 2017 10:26 AM

All replies

  • User-271186128 posted

    Hi PurpleHero,

    But when I publish it to my Azure App Service, login page etc works, but on one webform not buttons are working. I debugged by attaching debugger to AppService, th ebuttons are firing the event and all code is running fine but the webpage does not update with right data.

    How do you display the data? Please check whether you are using JQuery or not? You could also use F12 developer tools to check whether it contains JavaScript error.

    If possible, I suggest you could post the relevant code, it might be easier for us to help you.

    Besides, you could also refer to the following articles to debug your code step by step, and view the log.

    https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-dotnet-troubleshoot-visual-studio

    https://blogs.msdn.microsoft.com/benjaminperkins/2016/09/22/remote-debug-your-azure-app-service-web-app/

    Best regards,
    Dillion

    Friday, August 11, 2017 2:26 AM
  • User1317037654 posted

    Hi Dillion,

    Thanks for you answer. I created a new Webform and pasted most of the code behind. This one works. I get the impression I was doing something wrong with the UpdatePanels.

    Anyway, I am pasting my code for the not-working page here. The aspx code followed by the c# code. As I told you I debugged the code step by step in Visual Studio. The button code is working, all the variables get the required value, however what I see during step-by-step debugging is that after each line of code, the page is being refreshed with empty data.

    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site1.Master" CodeBehind="WebFormOrders1.aspx.cs" Inherits="WebApplication1.WebFormOrders1" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    
    
    <asp:Content  ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
      
        <style type="text/css">
        .modalBackground
        {
        background-color: Black;
        filter: alpha(opacity=90);
        opacity: 0.8;
    
    }
        .modalPopup
        {
        background-color: #FFFFFF;
        border-width: 3px;
        border-style: solid;
        border-color: black;
        padding-top: 10px;
        padding-left: 10px;
        width: 300px;
        height: 400px;
    
    }
    </style>
       
        
             <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
            
     <asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" Visible="false" />
     
    <!-- ModalPopupExtender -->
    <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="btnShow"
        CancelControlID="btnClose" BackgroundCssClass="modalBackground">
    </cc1:ModalPopupExtender>
            
    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" ScrollBars="Vertical" Height="400px" align="center" style = "display:none; background-color:antiquewhite; border-color:cornflowerblue;">
        <div>This is an ASP.Net AJAX ModalPopupExtender Example<br /></div>
        <asp:RadioButtonList ID="test" runat="server" DataSourceID="SQL1" DataTextField="ItemName" DataValueField="Item"></asp:RadioButtonList>
        <asp:SqlDataSource ID="SQL1" runat="server" ConnectionString="<%$connectionstrings:SICConnectionstring %>" SelectCommand="SELECT Item, ItemName from SIC_Item WHERE right(Item,len(item)-10) LIKE @Item"><SelectParameters><asp:ControlParameter Name="Item" ControlID="TextBoxRefSource" PropertyName="Text" /></SelectParameters></asp:SqlDataSource>
        <asp:Button ID="btnClose" runat="server" Text="Close" OnClick="btnClose_Click" />
        <asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Text="Button2" />
        <asp:Button ID="Button3" runat="server" OnClick="btnClose_Click" Text="Button3" />
    </asp:Panel>
    <!-- ModalPopupExtender -->
    
        <!--Autocomplete Extender -->
       
            
    
            
            <asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Panel ID="TopPanel" runat="server">
                    <style> 
                        input[type=text] {
                            width: 100px;
                            box-sizing: border-box;
                            border: 2px solid #ccc;
                            border-radius: 10px;
                            font-size: 16px;
                            padding: 12px 20px 12px 10px;
                            -webkit-transition: width 0.4s ease-in-out;
                            transition: width 0.4s ease-in-out;
                        }
                        
                        input[type=text]:focus {
                            width: 100px;
                        }
                    </style>
           
                   <asp:TextBox ID="TextBoxRefSource" CssClass="text-primary" runat="server" style="z-index: 1; left: 232px; top: 58px; ; height: 1px; width: 117px; right: 694px; bottom: 307px;" AutoPostBack="true"></asp:TextBox>
                        <cc1:AutoCompleteExtender ServiceMethod="GetCompletionList" MinimumPrefixLength="1"  
       CompletionInterval="10" EnableCaching="false" CompletionSetCount="1" TargetControlID="TextBoxRefSource"  
       ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false"></cc1:AutoCompleteExtender>
                    <asp:Button ID="ButtonGetItem" CssClass="btn btn-ec" runat="server" OnClick="ButtonGetItem_Click" style="z-index: 1;  left: 425px; top: 60px; ;width:107px; right: 489px; height: 28px;" Text="Search" />
                    <asp:Button ID="ButtonAddtoCart" runat="server" BackColor="Yellow" OnClick="Button2_Click" style="z-index: 1; left: 425px; top: 183px; ; width:163px;" Text="Add to Cart" />
                    <asp:Panel ID="OptionPanel"  runat="server" BackColor="SlateGray" Style="; top:150px; left:800px; height:100px; width:500px" ScrollBars="Vertical" BorderStyle="Solid" BorderColor="Red" Visible="false">
                   
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$connectionstrings:SICConnectionstring %>" SelectCommand="SELECT Item, ItemName from SIC_Item WHERE right(Item,len(item)-10) LIKE @Item"><SelectParameters><asp:ControlParameter Name="Item" ControlID="TextBoxRefSource" PropertyName="Text" /></SelectParameters></asp:SqlDataSource>
                    </asp:Panel>
                     <asp:RadioButtonList ID="RadioButtonList1" Visible="false" runat="server" AutoPostBack="true" Style="background-color:mistyrose;border:medium solid blue; top:102px; left:115px; width:400px; height:100px;"  OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" ></asp:RadioButtonList>
                    <asp:Button ID="ButtonResetCart" runat="server" OnClick="ButtonResetCart_Click" style="z-index: 1; left: 602px; top: 182px; " Text="Reset Cart" />
                    <asp:Label ID="LabelItemRef" runat="server" style="z-index: 1; left: 57px; top: 102px; ; width: 62px;" Text="Item Ref" BorderColor="#FF66CC" BorderStyle="Dotted" BorderWidth="2px" height="23px"></asp:Label>
                    <asp:Label ID="LabelSicoCode" runat="server" style="z-index: 1; left: 130px; top: 102px; ; width: 181px; height: 23px; right: 679px;" Text="Full Sicorax Code" BorderColor="#FF6699" BorderStyle="Dotted" BorderWidth="2px"></asp:Label>
                    <asp:Label ID="LabelItemName" runat="server" style="z-index: 1;color:black; font:italic 300 arial; box-shadow:rgb(0, 255, 144) 10px 10px; left: 320px; top: 102px; ; height: 50px; width: 382px;background-color:navajowhite; word-wrap:normal;word-break:break-all; right: 365px;" Text="Item Name" BorderColor="#FF6699" BorderStyle="Dotted" BorderWidth="2px"></asp:Label>
                    <asp:TextBox ID="TextBoxQty" runat="server" TextMode="Number" placeholder="Quantity" style="z-index: 1; left: 819px; top: 100px; ; width: 96px; height: 50px; border-style:dotted;border-color:deeppink" AutoCompleteType="Enabled" Font-Size="15pt"></asp:TextBox>
                        <asp:Label ID="LabelUnitPrice" runat="server" style="z-index: 1; left: 713px; top: 102px; ; width: 88px; right: 216px; height: 50px;" Text="Unit Price" BorderColor="#FF6699" BorderStyle="Dotted" BorderWidth="2px" Font-Size="15pt"></asp:Label>
                    <asp:Label ID="Label5" runat="server" style="z-index: 1; left: 132px; top: 65px; " Text="Item Reference:"></asp:Label>
                </asp:Panel>
                    </ContentTemplate>
            </asp:UpdatePanel>
       
            <asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="ButtonAddtoCart" EventName="click" />
                </Triggers>
                <ContentTemplate>
                    <asp:GridView ID="GridView1"  runat="server" ShowHeaderWhenEmpty="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" style="table-layout:fixed; z-index: 1; left: 50px; top: 232px; ; height: 40px; width: 600px" OnRowDeleting="GridView1_RowDeleting" GridLines="Vertical">
                        <AlternatingRowStyle BackColor="#DCDCDC" />
                        <Columns>
                            <asp:CheckBoxField HeaderText="Select" Visible="False" />
                            <asp:BoundField DataField="rowindex" HeaderText="Line No." Visible="False" />
                            <asp:BoundField DataField="Item Ref" HeaderText="Item Ref" ReadOnly="True">
                            <ControlStyle Width="100px" />
                            <FooterStyle Width="100px" Wrap="False" />
                            <HeaderStyle Height="50px" Width="130px" Wrap="True" />
                            <ItemStyle Width="100px" Wrap="False" />
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Item Code" DataField="ItemCode" visible="false"/>
                            <asp:BoundField DataField="Item Name" HeaderText="Item Name">
                            <ControlStyle Width="400px" />
                            <FooterStyle Width="4000px" Wrap="false"/>
                            <HeaderStyle Width="400px" Wrap="false"/>
                            <ItemStyle  Width="400px" Wrap="false" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Unit Price" HeaderText="Unit Price">
                            <HeaderStyle Width="100px" />
                            <ItemStyle Width="100px" />
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Qty" DataField="Quantity" >
                            <HeaderStyle Width="50px" />
                            <ItemStyle Wrap="False" Width="50px" />
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Sub Total" DataField="Sub Total">
                            <FooterStyle Wrap="False" />
                            <HeaderStyle Wrap="False" Width="150px" />
                            <ItemStyle Width="150px" Wrap="False" />
                            </asp:BoundField>
                            <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
                        </Columns>
                        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                        <PagerStyle ForeColor="Black" HorizontalAlign="Center" BackColor="#999999" />
                        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#0000A9" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#000065" />
                    </asp:GridView>
                    <asp:TextBox ID="TextBoxTotal" runat="server" Enabled="False" style="z-index: 1; left: 1035px; top: 232px; ; width: 204px"></asp:TextBox>
        
            <asp:Button ID="ButtonSendOrder" runat="server" OnClick="ButtonSendOrder_Click" CssClass="btn" style="z-index: 1; left: 1035px; top: 287px; ; width: 210px; height: 29px;" Text="Confirm and Send Order" />
        
            <asp:TextBox ID="TextBoxMSG" runat="server" Enabled="False" style="z-index: 1; left: 1034px; top: 318px; ; width: 205px"></asp:TextBox>
        
                </ContentTemplate>
    
            </asp:UpdatePanel>
            
            
        <asp:Label ID="LabelCart" runat="server" Font-Italic="True" style="z-index: 1; left: 242px; top: 420px; " Text="Cart Status"></asp:Label>
            
            
        <script src="Scripts/jquery-1.10.2.js"></script>
        <script src="Scripts/bootstrap.min.js"></script>
        <script src="Scripts/bootstrap.js"></script>
        <script src="Content/Site.css"></script>
          <link href="Content/bootstrap.css" rel="stylesheet" />
        <link href="Content/site.css" rel="stylesheet" />
     
        
     
    </asp:Content>
    
    
    And Code Behind:
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.Owin.Security;
    using System.Security.Claims;
    using WebApplication1.Models;
    using WebApplication1.Controllers;
    using AjaxControlToolkit;
    using System.Configuration;
    
    
    namespace WebApplication1
    {
        
        public partial class WebFormOrders1 : System.Web.UI.Page
        {
            public string SICDATAconnstring= System.Configuration.ConfigurationManager.ConnectionStrings["AzureConnectionString"].ConnectionString;// "Data Source=" + "192.168.9.207" + ";Initial Catalog=SICDATA_TS;MultipleActiveResultSets=True;Connection Timeout=1000; User ID=sa_aldreport; Password=sapass";
            public string LocalOrders = System.Configuration.ConfigurationManager.ConnectionStrings["AzureConnectionString"].ConnectionString;// "Data Source=" + "QBADMIN\\SQLEXPRESS" + ";Initial Catalog=ALDOrders;MultipleActiveResultSets=True;Connection Timeout=1000; User ID=sa; Password=flormar-89";
            public string SVR2010connstring = System.Configuration.ConfigurationManager.ConnectionStrings["AzureConnectionString"].ConnectionString;//"Data Source=" + "192.168.0.127" + ";Initial Catalog=ALD_Reports;MultipleActiveResultSets=True;Connection Timeout=1000; User ID=sa_aldreport; Password=sapass";
            public string AzureConnString = System.Configuration.ConfigurationManager.ConnectionStrings["AzureConnectionString"].ConnectionString;
            DataTable dt = null;
            public string Reference;
            public string gClientCode;
    
            public int rowcount
                    {
                get
                {
                    int retVal = 0;
                    if (ViewState["messageID"] != null)
                        Int32.TryParse(ViewState["messageID"].ToString(), out retVal);
    
                    return retVal;
                }
                set { ViewState["messageID"] = value; }
            }
            public Boolean isDelegateUser()
            {
                if (User.Identity.IsAuthenticated)
                {
                    var user = User.Identity;
                    ApplicationDbContext context = new ApplicationDbContext();
                    var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
                    var s = UserManager.GetRoles(user.GetUserId());
                    var user1 = UserManager.FindById(user.GetUserId());
                    gClientCode = user1.ClientCode;
                    try
                    {
                        // if (s[0].ToString() == "Delegate")
                        if ((user1.ClientType).Trim() == "03")
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch
                    {
    
                    }
                }
                return false;
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if ((User.Identity.IsAuthenticated) && isDelegateUser())
                {
                    if (!Page.IsPostBack)
                    {
                        dt = new DataTable();
                        MakeDataTable();
                        //  rowcount = 0;
                    }
                    else
                    {
                        dt = (DataTable)ViewState["DataTable"];
                        rowcount = (int)ViewState["MyROW"];
                    }
                    ViewState["DataTable"] = dt;
                    ViewState["MyROW"] = rowcount;
                    for (int i = 0; i < GridView1.Columns.Count; i++)
                    {
                        GridView1.Columns[i].ItemStyle.Width = 200;
                    }
                }  else
                {
                    Response.Redirect("~/AccessDenied.aspx");
    
                }
                BindGrid();
                TopPanel.DefaultButton = "ButtonGetItem";
            }
            private void MakeDataTable()
            {
                dt.Columns.Add("rowindex");
                dt.Columns.Add("Item Ref");
                dt.Columns.Add("ItemCode");
                dt.Columns.Add("Item Name");
                dt.Columns.Add("Unit Price");
                dt.Columns.Add("Quantity");
                dt.Columns.Add("Sub Total");
            }
    
    
            protected void ButtonGetItem_Click(object sender, EventArgs e)
            {
                ShowPopUpMsg("Your Order Reference is -1");
                SqlConnection conn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                SqlCommand cmd = new SqlCommand();
    
                conn.ConnectionString = SICDATAconnstring;
                comm.CommandType = CommandType.Text;
                comm.CommandTimeout = 100000;
                comm.CommandText = "select count(Item) as MYCOUNT FROM SIC_Item WHERE Right(Item, Len(Item) - 10) = '" + TextBoxRefSource.Text + "'";
                cmd.CommandType = CommandType.Text;
                cmd.CommandTimeout = 10000;
                cmd.CommandText = "select Item, ItemName, ItemUD4,UNitSelling FROM SIC_Item WHERE Right(Item, Len(Item) - 10) = '" + TextBoxRefSource.Text + "' ORDER by Item";
                DataSet ds = new DataSet();
                SqlDataAdapter sda = new SqlDataAdapter(cmd.CommandText, conn);
                sda.Fill(ds);
    
                    conn.Open();
                ShowPopUpMsg("Your Order Reference is 1");
                comm.Connection = conn;
                int MYCOUNT = System.Convert.ToInt32(comm.ExecuteScalar());
                cmd.Connection = conn;
                SqlDataReader reader;
                reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    if (MYCOUNT== 1)
                    {
                        ShowPopUpMsg("Your Order Reference is 2");
                        while (reader.Read())
                        {
                            if (!reader.IsDBNull(2))
                            {
                                RadioButtonList1.Visible = false;
                                LabelItemRef.Visible = true;
                                LabelSicoCode.Visible = true;
                                LabelItemName.Visible = true;
                                LabelUnitPrice.Visible = true;
                                TextBoxQty.Visible = true;
    
    
                                LabelItemRef.Text = TextBoxRefSource.Text;
                                LabelSicoCode.Text = reader.GetString(0);
                                // CA = reader.GetFloat(0);
                                LabelItemName.Text = reader.GetString(1);
                                LabelUnitPrice.Text =string.Format("{0:f2}", reader.GetDecimal(3));
                                TextBoxQty.Focus();
                                TopPanel.DefaultButton = "ButtonAddtoCart";
                                ShowPopUpMsg("Your Order Reference is 3");
                            }
                        }
    
                    }
                    else
                    {
    
                        // mp1.Show();
                        ShowPopUpMsg("Your Order Reference is R");
                        RadioButtonList1.DataSource = ds;
                        RadioButtonList1.DataTextField = "ItemName";
                        RadioButtonList1.DataValueField = "Item";
                        RadioButtonList1.Visible = true;
                        RadioButtonList1.DataBind();
                        LabelItemRef.Visible = false;
                        LabelSicoCode.Visible = false;
                        LabelItemName.Visible = false;
                        LabelUnitPrice.Visible = false;
                        TextBoxQty.Visible = false;
                        ButtonAddtoCart.Visible = false;
                        ButtonResetCart.Visible = false;
                    }
    
                }
                else
                {
                    ShowPopUpMsg("Your Order Reference is P");
                    LabelItemRef.Text = "Not Found";
                    LabelSicoCode.Text = "Not Found";
                    // CA = reader.GetFloat(0);
                    LabelItemName.Text = "Not Found";
                }
                ShowPopUpMsg("Your Order Reference is Z");
                ;
            }
            public void SearchbyItem(String MyItem)
            {
                SqlConnection conn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                SqlCommand cmd = new SqlCommand();
    
                conn.ConnectionString = SICDATAconnstring;
                comm.CommandType = CommandType.Text;
                comm.CommandTimeout = 100000;
                comm.CommandText = "select count(Item) as MYCOUNT FROM SIC_Item WHERE Item= '" + MyItem + "'";
                cmd.CommandType = CommandType.Text;
                cmd.CommandTimeout = 10000;
                cmd.CommandText = "select Item, ItemName, ItemUD4,UNitSelling FROM SIC_Item WHERE Item= '" + MyItem + "' ORDER by Item";
                DataSet ds = new DataSet();
                SqlDataAdapter sda = new SqlDataAdapter(cmd.CommandText, conn);
                sda.Fill(ds);
    
                conn.Open();
                comm.Connection = conn;
                int MYCOUNT = System.Convert.ToInt32(comm.ExecuteScalar());
                cmd.Connection = conn;
                SqlDataReader reader;
                reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
    
                    while (reader.Read())
                    {
                       // if (!reader.IsDBNull(2))
                       // {
                            RadioButtonList1.Visible = false;
                            LabelItemRef.Visible = true;
                            LabelSicoCode.Visible = true;
                            LabelItemName.Visible = true;
                            LabelUnitPrice.Visible = true;
                            TextBoxQty.Visible = true;
                        ButtonAddtoCart.Visible = true;
                        ButtonResetCart.Visible = true;
    
                            LabelItemRef.Text = TextBoxRefSource.Text;
                            LabelSicoCode.Text = reader.GetString(0);
                            // CA = reader.GetFloat(0);
                            LabelItemName.Text = reader.GetString(1);
                            LabelUnitPrice.Text = string.Format("{0:f2}", reader.GetDecimal(3));
                        TextBoxQty.Focus();
                        TopPanel.DefaultButton = "ButtonAddtoCart";
                        //}
                    }
    
    
                }
            }
    
            private void AddToDataTable()
            {
                if (TextBoxQty.Text!="")
                {
                    DataRow dr = dt.NewRow();
                    dr["Rowindex"] = rowcount;
                    dr["Item Ref"] = LabelItemRef.Text;
                    dr["ItemCode"] = LabelSicoCode.Text;
                    dr["Item Name"] = LabelItemName.Text;
                    dr["Unit Price"] = LabelUnitPrice.Text;
                    dr["Quantity"] = TextBoxQty.Text;
                    //   dr["Sub Total"] = System.Convert.ToDecimal(LabelUnitPrice.Text) * System.Convert.ToInt32(TextBoxQty.Text);
                    try
                    {
                        dr["Sub Total"] = string.Format("{0:f2}", (System.Convert.ToDouble(LabelUnitPrice.Text) * System.Convert.ToInt32(TextBoxQty.Text)));
                        //  dt.Rows.InsertAt(dr,dt.Rows.Count-1);
                    }
                    catch
                    {
    
                    }
                    dt.Rows.Add(dr);
                    Refreshtotal();
                    TextBoxRefSource.Focus();
                    //TopPanel.DefaultButton = "TextBoxRefSource";
                }
            }
            private void BindGrid()
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            GetCount();
            }
    
    
            protected void Button2_Click(object sender, EventArgs e)
            {
                rowcount = rowcount + 1;
                AddToDataTable();
                BindGrid();
    
            }
    
            protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
            {
                int myrowindex;
                 
               
                        dt.Rows.RemoveAt(e.RowIndex);
              
                BindGrid();
                Refreshtotal();
            }
            public void Refreshtotal()
            {
                double mytotal=0;
                foreach (DataRow DR in dt.Rows)
                {
                    mytotal = mytotal +System.Convert.ToDouble(DR["Sub total"]);
                }
                TextBoxTotal.Text = "Total: " + string.Format("{0:f2}", mytotal);
            }
            public void GetCount()
            {
                double TotalRows = 0;
                foreach (DataRow DR in dt.Rows)
                {
                    TotalRows = TotalRows +1;
                }
                if (TotalRows > 0)
                {
                    LabelCart.Text = string.Format("You have {0} items in your Shopping Cart." , string.Format("{0}", TotalRows));
                }
                else
                {
                    LabelCart.Text = "Your Shopping Cart is Empty.";
                }
                
            }
    
            protected void ButtonSendOrder_Click(object sender, EventArgs e)
            {
                SqlConnection conn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                SqlCommand cmd = new SqlCommand();
                SqlTransaction TR;
                string TimeStamp;
                //TimeStamp= DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz");
                TimeStamp=DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss.fff");
                Reference = gClientCode.Trim() + "_" + TimeStamp;
                conn.ConnectionString = LocalOrders;
    
                comm.CommandType = CommandType.Text;
                comm.CommandTimeout = 100000;
                comm.CommandText = "INSERT  INTO Order_Header (OrderReference, DelegateCode, OrderDate, OrderTime) VALUES (@OrderReference, @DelegateCode, @OrderDate, @OrderTime) ";
                comm.Parameters.Add("@OrderReference", SqlDbType.NChar);
                comm.Parameters.Add("@DelegateCode", SqlDbType.NChar);
                comm.Parameters.Add("@OrderDate", SqlDbType.Date);
                comm.Parameters.Add("@OrderTime", SqlDbType.Time);
                cmd.CommandType = CommandType.Text;
                cmd.CommandTimeout = 10000;
                cmd.CommandText = "INSERT INTO Order_Detail (OrderReference, Item, UnitPrice, Quantity, SubTotal) VALUES(@OrderReference, @Item, @UnitPrice, @Quantity, @SubTotal)";
                cmd.Parameters.Add("@OrderReference", SqlDbType.NChar);
                cmd.Parameters.Add("@Item", SqlDbType.NChar);
                cmd.Parameters.Add("@UnitPrice", SqlDbType.Decimal);
                cmd.Parameters.Add("@Quantity", SqlDbType.Int);
                cmd.Parameters.Add("@SubTotal", SqlDbType.Real);
                conn.Open();
                TR = conn.BeginTransaction(IsolationLevel.ReadCommitted);
                comm.Transaction = TR;
                comm.Connection = conn;
    
                comm.Parameters["@OrderReference"].Value =Reference;
    
                comm.Parameters["@DelegateCode"].Value = gClientCode;
                comm.Parameters["@OrderDate"].Value = System.DateTime.Now.Date;
                comm.Parameters["@OrderTime"].Value = System.DateTime.Now.TimeOfDay;
                comm.ExecuteNonQuery();
                cmd.Transaction = TR;
                cmd.Connection = conn;
                foreach(GridViewRow GR in GridView1.Rows)
                {
                    cmd.Parameters["@OrderReference"].Value = TimeStamp;
                    cmd.Parameters["@Item"].Value = GR.Cells[3].Text;
                    cmd.Parameters["@UnitPrice"].Value = System.Convert.ToDecimal(GR.Cells[5].Text);
                    cmd.Parameters["@Quantity"].Value = System.Convert.ToInt32(GR.Cells[6].Text);
                    cmd.Parameters["@SubTotal"].Value = System.Convert.ToDouble(GR.Cells[7].Text);
                    cmd.ExecuteNonQuery();
                }
                try
                {
                    TR.Commit();
                    TextBoxMSG.Text = "SUCCESS";
                    MsgBox(Reference, this.Page, this);
                    ShowPopUpMsg("Your Order Reference is " + Reference);
                   
                   // Panel1.Visible = true;
                    
                }
                catch (Exception ex)
                {
                    TR.Rollback();
                    TextBoxMSG.Text = "FAILED";
                }
                conn.Close();
            }
            private void ShowPopUpMsg(string msg)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                
                sb.Append("alert('");
                sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
                sb.Append("');");
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true);
            }
    
            protected void ButtonResetCart_Click(object sender, EventArgs e)
            {
                dt.Clear();
                BindGrid();
                Refreshtotal();
                Response.Redirect(Request.RawUrl);
              
            }
            public void MsgBox(String ex, Page pg, Object obj)
            {
                string s = "<SCRIPT language='javascript'>alert('" + ex.Replace("\r\n", "\\n").Replace("'", "") + "'); </SCRIPT>";
                Type cstype = obj.GetType();
                ClientScriptManager cs = pg.ClientScript;
                cs.RegisterClientScriptBlock(cstype, s, s.ToString());
            }
            public void MYTEST()
            {
                TextBoxMSG.Text = "BISTR";
            }
            protected void Button1_Click(object sender, EventArgs e)
            {
                mp1.Show();
            }
            protected void btnClose_Click(object sender, EventArgs e)
            {
                TextBoxMSG.Text = "ddd" + test.SelectedValue;
            }
    
            protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
            {
                SearchbyItem(RadioButtonList1.SelectedValue);
               // OptionPanel.Visible = false;
                RadioButtonList1.Visible = false;
    
            }
            [System.Web.Script.Services.ScriptMethod()]
            [System.Web.Services.WebMethod]
            public static List<string> GetCompletionList(string prefixText, int count)
            {
                
                return AutoFillProducts(prefixText);
            }
            private static List<string> AutoFillProducts(string prefixText)
            {
                SqlConnection conn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                WebFormOrders1 PageObject = new WebFormOrders1();
                conn.ConnectionString = PageObject.SICDATAconnstring;
                comm.CommandType = CommandType.Text;
                comm.Connection = conn;
                comm.CommandText = "SELECT RIGHT(Item, LEN(Item)-10) FROM SIC_Item WHERE RIGHT(Item, LEN(Item)-10) LIKE '%"+ prefixText +"%'";
                conn.Open();
                SqlDataReader reader;
                reader = comm.ExecuteReader();
                List<string> MyList=new List<string>();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        MyList.Add(reader.GetString(0));
                    }
                }
                reader.Close();
                conn.Close();
                return MyList;
    
    
            }
    
            protected void TextBoxClient_TextChanged(object sender, EventArgs e)
            {
                if (TextBoxRefSource.Text.Length==5)
                {
                    SqlConnection conn = new SqlConnection();
                    SqlCommand comm = new SqlCommand();
                    WebFormOrders1 PageObject = new WebFormOrders1();
                    conn.ConnectionString = PageObject.SICDATAconnstring;
                    comm.CommandType = CommandType.Text;
                    comm.Connection = conn;
                    comm.CommandText = "SELECT clisupname FROM vw_gdi_clientsupplier WHERE clientsupplier = '" + TextBoxRefSource.Text + "'";
                    conn.Open();
                    string cclientname="";
                    try
                    {
                        cclientname = comm.ExecuteScalar().ToString();
                    }
                    catch (Exception ex)
                    {
    
                    }
                   // ClientName.Text = cclientname;
                    conn.Close();
    
                    
    
    
                }
            }
        }
    }

    Friday, August 11, 2017 10:17 AM
  • User-271186128 posted

    Hi PurpleHero,

    I get the impression I was doing something wrong with the UpdatePanels.

    You could try to remove the Update Panels to verify whether the issue is related to the Update Panels.

    The button code is working, all the variables get the required value, however what I see during step-by-step debugging is that after each line of code, the page is being refreshed with empty data.

    From your code, it seems that you are using GridView to display the data, please check your code and make sure you have called the BindGrid method and make sure the DataTable (gridview datasource) is not empty.

    Best regards,
    Dillion

    Tuesday, August 15, 2017 8:00 AM