Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my form I designed some textboxes, dropdowns and submit & cancel buttons in separate update panels and some textboxes and dropdowns are designed without update panel,this all designed with jQuery.

When I am clicking cancel button it is clearing only those textboxes and dropdowns which are in updatepanel. So I took all controls in one update panel but then jQuery functions and codes stopped working.

Now should I take update panels to every single control? or have any other procedure?
Posted
Updated 10-Apr-15 0:30am
v2
Comments
John C Rayan 10-Apr-15 15:00pm    
No. you don't require update panel for every control. You can put all controls in one update panel. Why is your jquery not working. Can you post some code to look at?
Dawood Abbas 13-Apr-15 5:14am    
<div>


<div id="page-wrapper">
<asp:UpdatePanel ID="uplblMessage" runat="server"><contenttemplate>
<asp:Label ID="lblMessage" runat="server" ForeColor="Black" BackColor="Yellow" Visible="false">

<asp:Label ID="lblUserId" runat="server" Visible="false">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">


<ol class="breadcrumb">
<li>
Home
</li>
<li class="">Customer Stuff
</li>
<li class="active">Customer Registration
</li>
</ol>
</div>
</div>
<!-- /.row -->
<div class="panel panel-blue add">
<div class="panel-heading">

Customer Registration


</div>
<div class="panel-body add-body">
<div class="form-horizontal">

Personal Info


<div class="row-fluid col-md-12">
<div class="col-md-4 ">
<div class="control-group">
<label class="control-label col-md-6">Name</label>
<div class="controls col-md-6">
<asp:UpdatePanel ID="uptxtName" runat="server"><contenttemplate>
<asp:TextBox ID="txtName" runat="server" TabIndex="1">
<asp:Requiredfieldvalidator id="reqname" controltovalidate="txtname" runat="server" errormessage="Required" class="error"
forecolor="red">
<asp:Regularexpressionvalidator id="regname" controltovalidate="txtname" class="error2"
validationexpression="([aA-za-z])+( [aA-za-z]+)*" errormessage="Not Valid"
runat="server" forecolor="red">

<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCancel" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
</Triggers>

</div>
</div>
</div>
<div class="col-md-8 ">
<div class="control-group">
<label class="control-label col-md-6">S/o, D/o,W/o</label>
<div class="controls col-md-6">
<asp:UpdatePanel ID="uptxtSo" runat="server"><contenttemplate>
<asp:TextBox ID="txtSo" runat="server" TabIndex="2"><br />
<asp:regularexpressionvalidator id="regsodowo" controltovalidate="txtso" class="error"
validationexpression="([aA-za-z])+( [aA-za-z]+)*" errormessage="*enter 5-50 char only"
runat="server" forecolor="red">

<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCancel" EventName="Click" />

The reason your jQuery stops working is because all of the controls your events are attached to are destroyed then re-created when the updatepanel fires. You need to bear this in mind when attaching your events.

XML
<%@ Page Language="C#"  Inherits="WebTest.UpdatePanel" Codebehind="UpdatePanel.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
    <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "resize", "alert('x');", true);
            LabelTimeA.Text = LabelTimeB.Text = DateTime.Now.ToString();
        }
    </script>

    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" />

    <h2>Attach events using jQuery</h2>
    <p>
        In this example we attach mouseover events to the time label.  However the updatepanel
        removes and replaces the UpdatePanel's content.  The jQuery events were attached to the
        elements that were originally loaded, but they have gone and have been replaced with new
        elements that don't have the jQuery events attached, so the mouseover no longer
        works after the update.
    </p>
    <asp:UpdatePanel ID="UpdateA" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Label ID="LabelTimeA" runat="server" /><br />
        <asp:Button ID="ButtonUpdateA" runat="server" Text="Update" />
    </ContentTemplate>
    </asp:UpdatePanel>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=LabelTimeA.ClientID %>').mouseover(function () { $(this).css('font-weight', 'bold'); });
            $('#<%=LabelTimeA.ClientID %>').mouseout(function () { $(this).css('font-weight', 'normal'); });
        });
    </script>

    <h2>Attach events using PageRequestManager</h2>
    <p>
        In this example we attach the mouseover events via the PageRequestManager object.  The
        difference with this object is that it knows when the updatepanel has been triggered
        so its pageLoaded event fires not only on the initial load, but also on the updatepanel
        being triggered.  The updatepanel is removing the elements with the events attached as
        with the example above, however the add_pageLoaded event is now being fired so they are
        being re-attached after the updatepanel has replaced them.
    </p>

    <asp:UpdatePanel ID="UpdateB" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Label ID="LabelTimeB" runat="server" /><br />
        <asp:Button ID="ButtonUpdateB" runat="server" Text="Update" />
    </ContentTemplate>
    </asp:UpdatePanel>

    <script type="text/javascript">
        function pageLoad() {
            $('#<%=LabelTimeB.ClientID %>').mouseover(function () { $(this).css('font-weight', 'bold'); });
            $('#<%=LabelTimeB.ClientID %>').mouseout(function () { $(this).css('font-weight', 'normal'); });
        }

//        If you want to add your event event rather than using pageLoad you can do it this way
//        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(){
//            $('#<%=LabelTimeB.ClientID %>').mouseover(function () { $(this).css('font-weight', 'bold'); });
//            $('#<%=LabelTimeB.ClientID %>').mouseout(function () { $(this).css('font-weight', 'normal'); });
//        });

    </script>


    </form>
</body>
</html>
 
Share this answer
 
v2
Please share the code. Also you can trouble shoot your code by performing following steps:-

Make sure that the selectors which you are using are correct for those controls which are in update panel. Its reason is that the client ID changes when the controls are put in the Update panel.

Most probably you are trying to get controls by using ID in jquery which does not match with the IDs which are in the Update Panel.

You can also re factor your jquery code to get the controls by using class name instead of Ids.
 
Share this answer
 

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



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