Thursday, September 30, 2010

Jquery to get set read access IFrame content TextBox Value Data




Please visit my new Web Site WWW.Codedisplay.com



As you know that this days smart developers doesn't use IFRAME. But in our job always developers need to handle legacy systems. I found such type of legacy application. Now i am trying to modify the user requirement. To do that i need to read or access IFrame content as well as get or put some data from parent page to IFRAME. Since i did it thats why i want to share with you how one can access/read/get IFrame content controls like TextBox value as well as set the value from parent page to IFRAME using JQUERY.

Here is a simple output screenshot of my example:
IFRAME_Jquery

To complete this example first create the below asp.net aspx page. Which we used within the IFRAME:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Iframe_Page_Content.aspx.cs" Inherits="Iframe_Page_Content" %>

<!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>Child page placed into the IFrame</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label runat="server" ID="lblInfo">Iframe TextBox: </asp:Label>
    <asp:TextBox runat="server" ID="txtInfo"></asp:TextBox>
    </div>
    </form>
</body>
</html>
Now create the below asp.net master page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IFRame_Jquery.aspx.cs" Inherits="IFRame_Jquery" %>

<!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>How to Get Set Iframe Content Like TextBox Control Value Text Data</title>
    <script src="Script/jquery.js" type="text/javascript"></script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <iframe id="uploadIFrame" scrolling="no" frameborder="0" style="border-style: none; margin: 0px; width: 100%; height: 40px;" src="Iframe_Page_Content.aspx"></iframe>    
        <asp:Button runat="server" ID="btnSet" Text="Hello Jquery Developers !!" />
        <asp:Button runat="server" ID="btnGet" Text="Click to read Iframe TextBox Data !!" />
    </div>
    </form>
</body>
</html>
Now use the below JQUERY to get set value:
<script language="javascript">
        $(document).ready(function() {
            $("#btnSet").click(function() {
                var $currIFrame = $('#uploadIFrame'); 
                $currIFrame.contents().find("body #txtInfo").val($('#btnSet').val());
                return false;
            });
        });

        $(document).ready(function() {
            $("#btnGet").click(function() {
                var $currIFrame = $('#uploadIFrame'); 
                alert($currIFrame.contents().find("body #txtInfo").val());
                return false;
            });
        });

    </script>

Hope one can access IFRAME content as well as set the value from parent page to IFrame using JQUERY.

Code Explanation:
Here I have created an Object named currIFrame which holds the full IFrame reference. The contents() method is used to get full HTML code inside the IFRAME.The Find() method is used to find out the element. The rest of the code is self explanatory. Hope you can understand.

Script tested for:
1. Internet Explorer (IE)
2. Mozilla Firefox
3. Opera
4. Google Chrome

Monday, September 27, 2010

How to merge all files into one file using DOS command




Please visit my new Web Site WWW.Codedisplay.com



Some days ago one of my friend ask me a problem that he needs to import csv file to a SQL Server database. But the problem is there is a huge number of small files. He does not want to import one by one. He needs to merge or together all files in a single file so that he can import using SQL Server import wizard only one file. Since it was a one time job for reconcilation, I suggest him use a DOS command to merge all files into a single or one file. The DOS command is given below:










For example, you can join file1.txt and file2.txt to a new file named file3.txt:
copy/b file1.txt +file2.txt file3.txt
OR:
copy/b *.txt newfilename.txt
OR for all files in a folder:
copy/b * "newfilename_with_path"

Tuesday, September 21, 2010

Jquery to get SelectedValue SelectedIndex SelectedText of a DropdownList in Asp.net




Please visit my new Web Site WWW.Codedisplay.com



When you bind a DropdownList by data sometimes it may require to do something in the client side using javascript or jquery. To read the same post using javascript click here. In this article i will show you how one can get DropdownList SelectedValue, SelectedText & SelectedIndex. So that you can now play with Asp.net DropdownList control. The output like below:

Drodwnlist jquery

An example of complete code is given below:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>How to get Selected value, Selected index & Selected text of a DropDownList</title>
    <script src="Script/jquery.js" type="text/javascript"></script>
    
    
<script type="text/javascript">
        $(function () {
            $('select[id$=DropDownList1]').bind("change keyup", function () {
                $('#info').html(
                "<b>Selected Value:</b> " + $('#<%= DropDownList1.ClientID%>').val() +
                "<br />" +
                "<b>Selected Index:</b> " + $('#<%= DropDownList1.ClientID%>').get(0).selectedIndex +
                "<br />" +
                "<b>Selected Text:</b> " + $('select[id$=DropDownList1] :selected').text());
            });
        });
    </script>
        
</head>
<body>
    <form id="form1" runat="server">
    <div>
<h2>To display Selectedvalue, Selectedindex & Selectedtext please select an item from the DropDownList</h2>
        <asp:DropDownList ID="DropDownList1" runat="server" >
            <asp:ListItem Text="One" Value="1"></asp:ListItem>
            <asp:ListItem Text="Two" Value="2"></asp:ListItem>
            <asp:ListItem Text="Three" Value="3"></asp:ListItem>
            <asp:ListItem Text="Four" Value="4"></asp:ListItem>
            <asp:ListItem Text="Five" Value="5"></asp:ListItem>
        </asp:DropDownList>
        <hr /><br />
        <div id="info"></div>    </div>
    </form>
</body>
</html>

Code explanation:
The line $('#<%= DropDownList1.ClientID%>').val() will return you the selectedtext.
The line $('#<%= DropDownList1.ClientID%>').get(0).selectedIndex will return you the selectedindex
The line $('select[id$=DropDownList1] :selected').text()) will return you selectedtext.

Note:
Here i used two event change & keyup because the change event works in IE wheres keyup event works for Mozilla, Chrome and Safari.

Script Tested for the following browsers:
1. Internet Explorer (IE)
2. Mozilla Firefox
3. Opera
4. Google Chrome

Thursday, September 16, 2010

How to merge two or more files using C#




Please visit my new Web Site WWW.Codedisplay.com



Few days ago i have a requirement to make a processing engine which will download, decode & staging almost 70k+ ASN files. So that i have developed an ASN Decoder using Turbo C. Then make a DLL to use this decoder in my C# project. Everything is good but one problem is that my processing exe will take almost 6 hours to process all files. After reviewing my source code i found that each time my ASN Decoder DLL open a single file then decode it then close the file & also create a csv file for bulk insert into my database. I took a decission to reduce the time for open & closing a file. How i can do it? I made it by merging two or more or mutiple ASN files in a single file. So that my DLL need to open almost 1/3rd of files than earlier & my procesiing now takes only 2 hours. If you are facing such type of problem then you can follow my way.







C# Source code for merging mutiple files:
private void Form1_Load(object sender, EventArgs e)
        {
            string sASN1 = @"11.asn";
            string sASN2 = @"22.asn";

            FileStream FStream1 = null;
            FileStream FStream2 = null;

            FStream1 = File.Open(sASN1, FileMode.Append);
            FStream2 = File.Open(sASN2, FileMode.Open);
            byte[] FStream2Content = new byte[FStream2.Length];
            fs2.Read(FStream2Content, 0, (int)FStream2.Length);
            FStream1.Write(FStream2Content, 0, (int)FStream2.Length);

            MessageBox.Show("Merging Successfully ended!");

            FStream1.Close();
            FStream2.Close();
        }


Happy coding !!
Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash