Click here to Skip to main content
15,896,259 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a message box. it will refresh for every 1 sec with AJAX updatepanel.
i have a DIV (ID=cont) tag for message box scrollbar.the DIV tag is out side of the updatepanel.
Scrollbar positioned always bottom by the help of jQuery function.
now the problem is when new message was arrived the scrollbar not come down automatically.
i am tried to call jQuery function in updatepanel like this:

Sys.Application.add_load(updateDiv);


but no use.

What I have tried:

<form id="form2" runat="server">
    <div class="div" id="div" runat="server">
        <div id="cont" runat="server" class="cont">

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

        <asp:DataList ID="dt" runat="server" class="dt" onitemdatabound="dt_ItemDataBound">
        <ItemTemplate>

                 <p class="p" id="name" runat="server" style="margin-top:0px; display:none"><%#Eval("username") %></p>
                
                 <div class="div1" id="div1" runat="server">
                 <div id="message" runat="server" class="message"><%#Eval("message") %></div>
                 </div>

        </ItemTemplate>
        </asp:DataList>

        <asp:Timer ID="Timer1" runat="server" OnTick="GetTime" Interval="1000" />
        </ContentTemplate>
        </asp:UpdatePanel>

    </div>


    <div class="div2">
    <asp:TextBox ID="message" runat="server" TextMode="MultiLine" placeholder="Type Message" class="textbox"></asp:TextBox>
    <asp:Button ID="send" runat="server" Text="Send" class="send" 
            onclick="send_click" />
    <asp:RequiredFieldValidator ControlToValidate="message" ID="RequiredFieldValidator1" runat="server" ErrorMessage="Type message" ForeColor="Red"></asp:RequiredFieldValidator>
    </div>
    </div>
        <script src="Scripts/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
        
        var objDiv = document.getElementById("cont");
        objDiv.scrollTop = objDiv.scrollHeight;
        function updateDiv() {
            $("#here").load(window.location.href + " #here");
        }
    </script>
    </form>
Posted
Updated 12-Feb-18 8:14am
v3

1 solution

m new to Javascript and jQuery. I want to click a button and have a js function executed. (For this example, it's just an alert, but it's actually an ajax function.)

The first alert appears, but after I click the button, I never see the second ("did it") alert. It looks like javascript doesn't think the doIt() function is defined when the button is clicked.

Here's the relevant code:

$(document).ready(function()
{ 
    alert('ready');

    function doIt() {
        alert('did it');
    };
}
)

<body>
    <input name="Go" type="button" value="Go" onclick="doIt();"/>
</body>
 
Share this answer
 
Comments
Mukthahar Shaik 12-Feb-18 14:29pm    
helloo aaronzeng. you need to post this one in "ask a question". any way your solution is here:

<script src="jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">

    $(document).ready(function () {
        alert('ready');
        $("#go").click(function () {
            alert('did it');
        });
    });
 </script>

<body>
<input name="Go" id="go" type="button" value="Go" onclick="doIt();"/>
</body>


always use selector(class name, control id) to apply function.

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