Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi dear,

i have created one div on my page and add some controls in div as
XML
<table id="tbl_Main" runat="server">
            <tr id="tr_Moving" runat="server">
  <td id="td_Moving" runat="server">
                    <div id="DV_Moving" runat="server">
                    <ACT:DragPanelExtender ID="DragPanelExtender1" runat="server" TargetControlID="panel_TextComments"
                        DragHandleID="lbl">
                    </ACT:DragPanelExtender>
                    <asp:Panel ID="panel_TextComments" runat="server" BackColor="Snow" Width="250" HorizontalAlign="Center">
                        <asp:TextBox ID="txt_comments" runat="server"></asp:TextBox>
                        <asp:Label ID="lbl" runat="server" Text="Drag this"></asp:Label>
                    </asp:Panel>
                    </div>
                </td>
</tr>
</table>



On txt_comments onBlur event i have to check whether txt_comments contains valur or not.

If it has some value then create new div which id is DV_Moving at client side.

How can i achieve this?

Please please guide me.

So so thanks in advance
Posted
Updated 15-Jun-11 22:03pm
v2
Comments
Sergey Alexandrovich Kryukov 16-Jun-11 4:00am    
APS.NET? Tag it!
--SA
Alizee@CP 16-Jun-11 4:03am    
Created...

Do something like this. I am adding div after table with id tbl_main
<script>
 $(document).ready(function(){

$("#<%=txt_comments.ClientID%>").blur(function(){

  if(this.val() != "")
{
 ('<div id="DV_moving"></div>').insertAfter('#tbl_Main');

}

});

});
</script>
 
Share this answer
 
v3
Comments
Alizee@CP 16-Jun-11 5:33am    
Thanks kiran....

But i dont know how this function get called?
Kiran Sonawane 16-Jun-11 5:36am    
Are aware with Jquery. Above code is jquery in which ready function will get called after your page loaded completely and I am inserting div on blur event of textbox
Alizee@CP 16-Jun-11 5:38am    
Ok. thanks .

I will try this
Alizee@CP 16-Jun-11 5:41am    
ERROR OCCURS THAT PREVENT THIS PAGE FROM CREATING ADDITIONAL DIALOGUES.
Kiran Sonawane 16-Jun-11 5:44am    
I think you don't have jquery JS files in your project. Will send javascript code after while
hi try this example, this might help you.

 <script type="text/javascript">
$(document).ready(function(){
 
$("#<%=txt_comments.ClientID%>").blur(function(){
 
  if(this.val() != "")
{
  creatediv('DV_Moving', 'your data inside the DIV', 'width', 'height');
}
 
});
 
});

        function creatediv(id, html, width, height) {
            var newdiv = document.createElement('div');
            newdiv.setAttribute('id', id);
            if (width) {
                newdiv.style.width = 300;
            }
            if (height) {
                newdiv.style.height = 300;
            }
            newdiv.style.background = "#00C";
            newdiv.style.border = "4px solid #000";
            if (html) {
                newdiv.innerHTML = html;
            } else {
                newdiv.innerHTML = "nothing";
            } 
            document.body.appendChild(newdiv);
        }
    </script>
 
Share this answer
 
v3
Comments
Alizee@CP 16-Jun-11 6:04am    
Nothing happens from this also
tanweer 16-Jun-11 6:09am    
hi, try putting an alert inside your blur event to check either this event is firing or not.
Alizee@CP 16-Jun-11 6:32am    
Hey tanweer,

Its working dude.
I replace 'your data inside the DIV' and out html text box there so it displayed well.

But my need to display all which i mentioned in my question.
I am using ajax control there , and asp panel control.

How do i create it here ?
tanweer 16-Jun-11 6:12am    
I also notice that the if statement is not good, use

if($(this).val() != "") instead of if(this.val() != "")
Alizee@CP 16-Jun-11 6:34am    
Hey tanweer, Its working dude. I replace 'your data inside the DIV' and out html text box there so it displayed well. But my need to display all which i mentioned in my question. I am using ajax control there , and asp panel control. How do i create it here ?
Try this,
C#
body = document.getElementsByTagName("body").item(0);
        //Creating a table
        table = document.createElement("TABLE");
        body.appendChild( table );
        table.setAttribute( "border", 2 );
        table.setAttribute( "id", "mytab" );
        //Adding table body to table
        tablebody = document.createElement("TBODY");
        table.appendChild(tablebody);
        //Adding row object to a table body
        row=document.createElement("TR");
        tablebody.appendChild(row);
        row.setAttribute("border",2);
        //Adding a cell object to a row
        cell=document.createElement("TD");
        cell.setAttribute("border",2);
        cell = row.insertCell();
        cell.innerHTML = "Start";
        cell = row.insertCell();
        cell.innerHTML = "Distance";
        cell = row.insertCell();
        cell.innerHTML = "Stop";
 
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