本文介绍了javascript fun在更新面板内部无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

html



html

  <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)

{

Te xtBox 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();

}



}



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();
}

}

推荐答案


// bind the events (jQuery way)






--Amy


这篇关于javascript fun在更新面板内部无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:29