locked
open notepad by clicking on button from Repeater Control RRS feed

  • Question

  • User1878568433 posted

    I have one Repeater Control.In that one column (Image Button)Named as notepad.

    I wanted to know when I will click this notepad button on repeater control notepad will open with some data.

    how to do this.

    Please help me

    Thursday, February 1, 2018 9:18 AM

All replies

  • User-492460945 posted

    Hello sripadasatpathy,

    I think this issue was already explained in ASP.Net forums here.

    Thanks,

    Rajesh.

    Thursday, February 1, 2018 9:54 AM
  • User1400794712 posted

    Hi sripadasatpathy,

    When the button inside the repeater control, we can use the Command event of repeater control to check if we click on the button.

    I made a demo, you can take it as a reference.

    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand">
    <HeaderTemplate>
    <table>
    <tr>
    <th>Name</th>
    <th>Age</th>
    <th>Action</th>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td bgcolor="#CCFFCC">
    <asp:Label runat="server" ID="Name"
    Text='<%# Eval("Name") %>' />
    </td>
    <td bgcolor="#CCFFCC">
    <asp:Label runat="server" ID="Age"
    Text='<%# Eval("Age") %>' />
    </td>
    <td bgcolor="#CCFFCC">
    <%--<asp:Button ID="Button1" runat="server" Text="Notepad" CommandName="Notepad" />--%>
    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Content/case0125_2.png" CommandName="Notepad"/>
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXX %>" SelectCommand="SELECT * FROM [Students]"></asp:SqlDataSource>
    </div>
    </form>
    </body>

    CS code:

    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
    if (e.CommandName == "Notepad")
    {
    var name = ((Label)e.Item.FindControl("Name")).Text;
    var age = ((Label)e.Item.FindControl("Age")).Text;
    using(StreamWriter w = File.CreateText("D://Daisy//log1.txt"))
    {
    w.Write("Name:"+ name + "\r\n");
    w.Write("Age :"+ age + "\r\n");
    }
    //File.Open("D://Daisy//log.txt", FileMode.Open);
    System.Diagnostics.Process.Start("notepad.exe", "D://Daisy//log1.txt");
    }
    }

    How it works:

    Best Regards,

    Daisy

    Friday, February 2, 2018 6:29 AM
  • User541108374 posted

    Hi,

    System.Diagnostics.Process.Start("notepad.exe", "D://Daisy//log1.txt");
    

    This will open notepad on the server (after giving the process under which the web application runs enough privileges [don't do that unless absolutely necessary as it poses potential security risks]) and not on the client which I tink is the intent of the person who started the thread.

    To respond to the original question: it's not possible with default ASP.NET. What you could try, and I'm not a fan of this, is to make use of a custom written ActiveX component that could open notepad on the client. Note that ActiveX has only support in Internet Explorer (didn't try Edge but likely it's out of there).

    Another solution would be to use JavaScript to copy a piece of text to the clipboard when pressing a button in the Repeater control and then show a message that it got copied to the clipboard. The enduser can then start any application she/he desires to paste the information in. Take a look at https://www.google.be/search?source=hp&ei=wZyKWuScItHLwQLu-4rgCA&q=javascript+copy+to+clipboard&oq=javascript+copy+to+clip&gs_l=psy-ab.3.0.0l10.588.4215.0.5801.23.17.0.0.0.0.301.2572.0j11j2j1.14.0....0...1.1.64.psy-ab..9.14.2564...0i131k1j35i39k1j0i203k1.0.A85Xm-44_Hw on how to do so.

    Kris.

    Monday, February 19, 2018 9:46 AM