Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
html

XML
  <asp:ScriptManager ID="scr" runat="server" EnablePageMethods="true"></asp:ScriptManager>
    <asp:UpdatePanel ID="up1" runat="server">
        <ContentTemplate>
    <script>

   function popuplogin() {

            var objpopup = document.getElementById('Main_popupdiv');
            var objblur = document.getElementById('divblur');
            objblur.setAttribute("class", "parentdiasble");
            objblur.removeAttribute("style");
            objpopup.setAttribute("style", "visibility:visible;display:block;position:absolute;margin-left:400px;z-index:10;");

        }

    </script>
            <div id="form1" runat="server">
                <div class="errordiv">
                    <asp:Label ID="Lbl_error" runat="server" Text=""></asp:Label>
                </div>
                <div id="detail_whole">
                    <asp:Repeater ID="detail_repeat" runat="server">
                        <ItemTemplate>
                            <div class="detail_image">
                                <img src='<%#getpath()%><%# DataBinder.Eval(Container.DataItem, "Image")%>' />
                            </div>
                            <div id="detail_details">
                                <div class="detail_content">
                                    <div class="detail_label">
                                        <asp:Label runat="server" Text="PRODUCT NAME"></asp:Label>
                                    </div>
                                    <div class="detail_value">
                                        <asp:Label ID="lbl_productname" runat="server" Text='<%# Eval("product_name") %>'></asp:Label><br />
                                    </div>
                                </div>
                                <div class="detail_content">
                                    <div class="detail_label">
                                        <asp:Label runat="server" Text="PRODUCT QUANTITY"></asp:Label>
                                        <asp:Label ID="lbl_quanstar" runat="server" Text="" Style="color: red">*</asp:Label>
                                    </div>
                                    <div class="detail_value">

                                        <asp:TextBox ID="txt_quan" runat="server" Width="20px" Text=""></asp:TextBox><br />

                                        <asp:RequiredFieldValidator ID="Rreqval_quantity" runat="server" ValidationGroup="detail" ControlToValidate="txt_quan" ErrorMessage="Quantity is mandatory"></asp:RequiredFieldValidator>

                                    </div>

                                </div>
                                <div class="detail_content">
                                    <div class="detail_label">
                                        <asp:Label runat="server" Text="PRODUCT PRICE"></asp:Label>
                                    </div>
                                    <div class="detail_value">
                                        <asp:Label ID="lbl_price" runat="server" Text='<%# Eval("price")%>'></asp:Label><br />
                                    </div>
                                </div>
                                <div class="detail_content">
                                    <div class="detail_label">
                                        <asp:Label runat="server" Text="PRODUCT DESCRIPTION"></asp:Label>
                                    </div>
                                    <div class="detail_value">
                                        <asp:Label ID="lbl_description" runat="server" Text='<%# Eval("descrip")%>'></asp:Label><br />
                                    </div>
                                </div>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
                <div id="div_wholeuser" class="div_wholeuser">

                    <div class="div_usercontrol">

                        <div class="images_usercontrol">
                            <purchase_webusercontrol:purchase_webusercontrol ID="purchase_webusercontrol" runat="server" cssclass="repeat_wholeusercontrol " />
                        </div>
                    </div>
                </div>
            </div>
<%-- <script type="text/javascript">

     Sys.Application.add_click(popuplogin);
            </script>--%>

            <asp:LinkButton ID="btn_purchase" runat="server" CssClass="addbutton" Text="Add To Cart" ValidationGroup="detail" OnClientClick="popuplogin()" OnClick="btn_purchase_Click">Add To Cart</asp:LinkButton>
        </ContentTemplate>

    </asp:UpdatePanel>


    <div id="popupdiv" runat="server" style="display: none;">

        <table>
            <tr>
                <td><span class="txt">UserName: <span class="redstar">*</span> &nbsp;&nbsp;</span></td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server" placeholder=" UserName"
                        Width="186px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvUserName" runat="server"
                        ErrorMessage="Please enter  User Name" ControlToValidate="txtUserName" ValidationGroup="Login"
                        Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <span class="txt">Password: <span class="redstar">*</span> &nbsp;&nbsp;</span>

                </td>
                <td>
                    <asp:TextBox ID="txtPwd" runat="server" TextMode="Password" placeholder=" Password" Width="186px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                        ControlToValidate="txtPwd" Display="Dynamic" ValidationGroup="Login"
                        ErrorMessage="Please enter Password" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:Button ID="btnSubmit" ValidationGroup="Login" runat="server" Text="Login" OnClick="btnSubmit_Click" />
                    <asp:Button ID="btnclose" runat="server" Text="Cancel" CausesValidation="false" Style="height: 26px" /></td>
            </tr>

            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>

        </table>
    </div>


code behind

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{

}
product_id = Convert.ToInt32(Request.QueryString["Product_id"]);


DataTable dt=objdetailpage.detailpage(product_id);
detail_repeat.DataSource = dt;
Category_ID = dt.Rows[0]["product_catid"].ToString();
detail_repeat.DataBind();

purchase_webusercontrol.parent_ID = Convert.ToInt32(Category_ID);
purchase_webusercontrol.product_ID = product_id;


}

protected void btnSubmit_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("popupid_sp", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name", txtUserName.Text);
int n = Convert.ToInt32(cmd.ExecuteScalar());
HttpCookie useridCookie = new HttpCookie("useridCookie");
useridCookie.Value= Convert.ToString(n);
Response.Cookies.Add(useridCookie);
con.Close();

}

protected void btn_purchase_Click(object sender, EventArgs e)
{
if (Request.Cookies["useridCookie"] == null )
{
ScriptManager.RegisterStartupScript(Page, typeof(Page), "Popup", "popuplogin()", true);
}
else
{
con.Open();
SqlCommand com1 = new SqlCommand("cartimage_sp", con);
com1.CommandType = CommandType.StoredProcedure;
com1.Parameters.AddWithValue("@id", product_id);
med_imgPath = Convert.ToString(com1.ExecuteScalar());

SqlCommand com = new SqlCommand("cart_sp", con);
com.CommandType = CommandType.StoredProcedure;

foreach (RepeaterItem ri in detail_repeat.Items)
{
TextBox quantitytext = ri.FindControl("txt_quan") as TextBox;
Label productprice = ri.FindControl("lbl_price") as Label;

quantityText = quantitytext.Text;
productpriceText = productprice.Text;

}
com.Parameters.AddWithValue("@product_id", product_id);
com.Parameters.AddWithValue("@buyerid", Convert.ToInt32(Request.Cookies["useridCookie"].Value));
com.Parameters.AddWithValue("@cartquantity", quantityText);
com.Parameters.AddWithValue("@addedamount", productpriceText);
com.Parameters.AddWithValue("@simage", med_imgPath);

com.ExecuteNonQuery();
Lbl_error.Text = "Cart has been added!!!";
Context.Server.Transfer("viewcart.aspx");
con.Close();
}

}
Posted

Please look at the solutions already mentioned here:

Javascript not working inside Updatepanel[^]

See if any of the solutions helps you out!
 
Share this answer
 
This happens due to the Partial Postback of your page using UpdatePanel. When you do the partial postback, the DOM is recreated and the javascript events are lost. In this case you need to rebind the control events.

Try this:
JavaScript
// bind the events (jQuery way)
$(document).ready(function() {
    popuplogin();   
});

// attach the event binding function to every partial update
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(evt, args) {
    popuplogin();
});


--Amy
 
Share this answer
 
Comments
shanmugaprabu198512 19-Oct-15 9:24am    
hi amy, i tried this still its not working. could u give some other idea.
shanmugaprabu198512 19-Oct-15 9:30am    
Error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 404 [getting this error] kindly help.

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900