Total Pageviews

Saturday 26 September 2015

Autocomplete for a input text box with update panel

SCRIPT
----------

 <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script>


      <script>
        $(document).keypress(function (event) {
            if (event.keyCode == 13) {
                $("#<%= pm_search_btn.ClientID%>").click();
            }
        });
    </script>

   <script type="text/javascript">

       $(document).ready(function () {
           SearchText_m();
       });

       //On UpdatePanel Refresh.
       var prm = Sys.WebForms.PageRequestManager.getInstance();
       if (prm != null) {
           prm.add_endRequest(function (sender, e) {
               if (sender._postBackSettings.panelsToUpdate != null) {
                   SearchText_m();
               }
           });
       };
       function SearchText_m() {
           $(".autosuggest").autocomplete({
               source: function (request, response) {
                   $.ajax({
                       type: "POST",
                       contentType: "application/json; charset=utf-8",
                       url: "meetings.aspx/GetAutoCompleteData",
                       data: "{'search_txt':'" + document.getElementById('txtSearch').value + "'}",
                       dataType: "json",
                       success: function (data) {
                           response(data.d);
                       },
                       error: function (result) {
                           alert("Error");
                       }
                   });
               }
           });
       }

    </script>


HTML (meetings.aspx)
--------

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

  <asp:UpdatePanel ID="UpdatePanel1"
                        UpdateMode="Conditional"
                        runat="server">
                        <ContentTemplate>

<input type="text" id="txtSearch" placeholder="Search..." class="autosuggest" name="pm_search_txt" />

 <span style="display:none">

 <asp:Button ID="pm_search_btn" runat="server" Text="Button" OnClick="pm_search_btn_Click" />
       </span>

         </ContentTemplate>
                    </asp:UpdatePanel>



Code Behind
---------------

using System.Web.Services;  


 [WebMethod]

    public static List<string> GetAutoCompleteData(string search_txt)
    {
        List<string> result = new List<string>();
        string conn = ConfigurationManager.ConnectionStrings["meeting_mdf"].ConnectionString;
        using (SqlConnection con = new SqlConnection(conn))
        {
            using (SqlCommand cmd = new SqlCommand(" select top 10 ministry from (select DISTINCT  ministry from customer_ad )  as tb1 where  ministry  LIKE '%'+@SearchText+'%'", con))
            {
                con.Open();
                cmd.Parameters.AddWithValue("@SearchText", search_txt);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    result.Add(dr["ministry "].ToString());
                }
                return result;
            }
        }
    }


Now you can get data
 protected void pm_search_btn_Click(object sender, EventArgs e)
{

}


Friday 25 September 2015

How to save a video in folder after upload in asp.net

In aspx file
---------------

using System;
using System.Web;
using System.IO;


file.SaveAs(Server.MapPath("~/videos/") + file.FileName);
Stream streamfile = file.InputStream;


OR

In ashx file
---------------

using System;
using System.Web;
using System.IO;


  HttpPostedFile file = null;

        if (context.Request.Files.Count > 0)
        {
            file = context.Request.Files[0];
            file.SaveAs(HttpContext.Current.Server.MapPath("~/videos/") + file.FileName);
            Stream streamfile = file.InputStream;
        }

Dynamic video gallery +flowplayer + Bootstrap modal + Asp.net

We will display a dynamic video gallery from database to datalist and on clicking a video, a bootstrap modal (pop up window) will display the video, also we will add a jquery to stop video on close.


SCRIPT (Jquery+Flowplayer+Bootstrap)
--------
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>

      <script src="//releases.flowplayer.org/6.0.3/flowplayer.min.js"></script>
    <link rel="stylesheet" href="//releases.flowplayer.org/6.0.3/skin/minimalist.css">



 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>



  //Stop video
   <script>
 
        $('body').on('hidden.bs.modal', '.modal', function () {
            $('video').trigger('pause');
       
        });
    </script>


(also u can try to stop video option 2:  

  <script>

        $('body').on('hidden.bs.modal', '.modal', function () {
           jQuery('.modalid video').attr("src", jQuery(".modalid video").attr("src"));
     
        });
    </script>

)

HTML (Datalist with flowplayer and bootstrap modal)
---------
<asp:DataList ID="test_datalist" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" CellPadding="10" RepeatLayout="Table" HeaderStyle-VerticalAlign="Top">
                            <ItemStyle Height="100%" HorizontalAlign="Center" />
                            <ItemTemplate>
                           <div class="test_first_div" style="padding-left: 2px;">
                         <div class="videobox" style="margin: 0 auto; width: 99%;">
                       <div style="float: left;width:100%;">
                       <div style="text-align: center; width: 100%; height: 40px; padding-top: 5px;">
                                                <span></span>
 <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Name") %>' CssClass="linkbtn2"></asp:LinkButton>

                          </div>

                           

                                           
                                        
      <a class="btn btn-info btn-lg" data-toggle="modal" data-target='<%# "#" + Eval("id") %>' >
        <img src="Images/Testimonies_poster.png"   style="width:100%"/>
    </a>

                                            <!-- Modal -->

  <div id='<%# Eval("id") %>' class="modal fade modalid" role="dialog">
                                                <div class="modal-dialog">

                                                    <!-- Modal content-->
                                             <div class="modal-content">
                                      <div class="modal-header">
                                   <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                            <h4 class="modal-title">Modal Header</h4>
                                                        </div>
                                                        <div class="modal-body" style="height:400px;">
                                                            <div class="videoplayer" style="">
 <div class="flowplayer" data-ratio="0.4167" data-poster="Images/Testimonies_poster.png">
                         <video poster=" width="300" height="400">

                                                      <source src='<%# Eval("location") %>' type='video/mp4' />
                                                       <source src='<%# Eval("location") %>' type='video/webm' />
                                                        <source src='<%# Eval("location") %>' type='video/ogg' />
                                                          <source src='<%# Eval("location") %>' type='video/flv' />
                                                                    </video>
                                                                </div>
                                                            </div>
                                                        </div>
                                                       
                                                    </div>

                                                </div>
                                            </div>
                                           
          

                                            <div style="text-align: left; width: 100%; height: 40px;">
                                                <span>Category :</span>
            <asp:Label ID="LinkButton3" runat="server" Text='<%# Eval("category") %>'></asp:Label>
                                                <br />
                                                <span>Posted on :</span>
  <asp:Label ID="LinkButton2" runat="server" Text='<%# Eval("Posted_date") %>'></asp:Label>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </ItemTemplate>

                        </asp:DataList>




You can now code behind to get data 

like Id,Name,videolocation,posted date etc .. and bind to datalist.

 test_datalist.DataSource = idr;

 test_datalist.DataBind();