There is a call button that pops a modal up then there is another button that submits the data in modal to database using juery but when i clcik the insert button on modal it throws error undefinded
here is the whole code
<div class="modal fade" id="myModalshare" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button><h4 class="modal-title" id="H2">
Share to Followers</h4></div><div class="modal-header" style="background-color: #E8F5FD">
<textarea name="comments2" rows="1" cols="20" id="comments2" class=" form-control"
placeholder="Comment"></textarea> </div><div id="modalbody" class="modal-body">
<div class="tblCustomer">
<div>
<span class="pull-left " style="margin-right: 8px">
<asp:Image ID="Imageuser" runat="server" ImageUrl='<%# String.Format("PROFILEPHOTOS/{0}",Eval("ImageName").ToString()) %>'
class="imageuser media-object img-rounded animated fadeInDown" Style="width: 45px; height: 45px;" />
<div class="clearfix">
</div>
</span>
<div class="pull-left " style="">
<div class="clearfix">
</div>
</div>
<div class="pull-left " style="">
<span class="name" style="font-family: Arial, Helvetica, sans-serif; font-weight: bold">
<%# Eval("Name") %></span>
<span class="senddate" style="font-family: Arial, Helvetica, sans-serif; font-weight: bold">
<%# Eval("SendDate") %></span>
<span class="username">
<%# Eval("UserName") %>
</span>
</div>
<div class=" " style="">
</div>
<div class="clearfix">
</div>
<div class="" style="margin-bottom: 4px">
</div>
<span class="contentpost" style="font-family: Arial, Helvetica, sans-serif; font-weight: normal">
<%# Eval("ContentPost") %>
</span>
<br />
<div class="clearfix">
</div>
<span></span>
<span class="id" style="font-size:0; color: #FFFFFF">
<%# Eval("ID") %></span>
<a >
<span class="imagename1" style="font-size: large">
<%# Eval("ImageName1") %>
</span>
</a>
<span class="path" style="font-size:large"><%# Eval("Path") %></span>
</div>
</div>
</div>
<div class="modal-footer">
<asp:LinkButton ID="btnSave" runat="server" CssClass="btn btn-info " BorderStyle="Solid"
BorderWidth="1" BorderColor="#007ACC">
<div class="">
<span class="" style="">
</span><span>
<asp:Label ID="Label61" runat="server" Text="post" Font-Bold="True" Font-Size="Large"></asp:Label>
</span>
</div>
</asp:LinkButton></div></div></div>
</div>
<script type="text/javascript">
$(function () {
$('[id*=Button1]').click(function () {
var id = $(this).closest('tr').find($('[id*=ProdID]')).text();
$('[id*=myModalshare]').modal('show');
$.ajax({
type: "POST",
url: "Timeline.aspx/GetNameUserName",
data: '{id:"' + id + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
// clear old value
$(".id").html('');
$(".imageuser").attr('src', '');
$(".username").html('');
$(".name").html('');
$(".senddate").html('');
$(".contentpost").html('');
$(".imagename1").html('');
$(".path").html('');
// Assign new value
if (response.d.length > 0) {
$(".id").html(response.d[0].Id);
$(".imageuser").attr('src', 'PROFILEPHOTOS/' + response.d[0].Imageuser);
$(".username").html(response.d[0].UserName);
$(".name").html(response.d[0].Name);
$(".senddate").html(response.d[0].SendDate);
$(".contentpost").html(response.d[0].ContentPost);
$(".imagename1").html(response.d[0].imagename1);
$(".path").html(response.d[0].path);
}
},
});
return false;
});
$('[id*=btnSave]').click(function () {
// var id = "1";
var id = $('.id').html().trim();
var name = $('.name').html().trim();
var username = $('.username').html().trim();
var contentPost = $('.contentpost').html().trim();
var senddate = $('.senddate').html().trim();
var imagename1 = $('.imagename1').html().trim();
var path = $('.path').html().trim();
// If you ant to insert "PROFILEPHOTOS/Test.jpg" format then use the below line
var imageuser = $('.imageuser').attr('src').slice(($('.imageuser').attr('src').lastIndexOf('/') + 1), $('.imageuser').attr('src').length);
// var imagename1 = $('.imagename1').attr('src').slice(($('.imagename1').attr('src').lastIndexOf('/') + 1), $('.imagename1').attr('src').length);
//If you ant to insert "Test.jpg" format then use the below line
var comments = $("#comments2").val();
$.ajax({
type: "POST",
url: "Timeline.aspx/InsertCommenttype",
data: '{id:"' + id + '",name:"' + name + '",username:"' + username + '",contentpost:"' + contentPost + '",comments:"' + comments + '",senddate:"' + senddate + '",imagename1:"' + imagename1 + '",path:"' + path + '",imageuser:"' + imageuser + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$('#myModalshare').modal('hide');
$("#lblText").html('Post Shared Successfully.');
$('#dialog1').fadeIn('slow').delay(1000).fadeOut('slow');
// clear value
$(".id").html('');
$(".imageuser").attr('src', '');
$(".username").html('');
$(".name").html('');
$(".senddate").html('');
$(".contentpost").html('');
$(".imagename1").html('');
$(".path").html('');
},
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
return false;
});
});
</script>
[WebMethod]
public static string InsertCommenttype(string id, string name, string username, string contentpost, string senddate, string comments, string imageuser, string imagename1, string path)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO [SHAREPOSTS](UserName,FriendUserName,fName,ShareContent,POSTID,SharePostDate,Comments,FImageName,ShareImageName,TotalCount,SharePath) VALUES(@UserName,@FriendUserName,@fName,@ShareContent,@POSTID,@SharePostDate,@Comments,@FImageName,@ShareImageName,@TotalCount,@SharePath)"))
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
// cmd.Parameters.AddWithValue("@ID", id);
cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.Session["userName"].ToString());
cmd.Parameters.AddWithValue("@FriendUserName", username);
cmd.Parameters.AddWithValue("@fName", name);
cmd.Parameters.AddWithValue("@ShareContent", contentpost);
cmd.Parameters.AddWithValue("@SharePostDate", senddate);
cmd.Parameters.AddWithValue("@POSTID", id);
cmd.Parameters.AddWithValue("@Comments", comments);
cmd.Parameters.AddWithValue("@FImageName", imageuser);
cmd.Parameters.AddWithValue("@ShareImageName", imagename1);
cmd.Parameters.AddWithValue("@TotalCount", 1);
cmd.Parameters.AddWithValue("@SharePath", path);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
return "Submited";
// return result;
}