I solved this problem duplicating the javascript function and put the second in pageLoad function. I changed the asp.net button to html button and call the Capture function in the onclick, to avoid unnecessary page load.
<script type="text/javascript">
var pageUrl = '<%=ResolveUrl("~/frmVisitasPorSetor.aspx") %>';
$(function() {
jQuery("#webcam").webcam({
width: 220,
height: 165,
mode: "save",
swffile: '<%=ResolveUrl("~/App_Themes/Webcam_Plugin/jscam.swf") %>',
debug: function(type, status) {
// $('#camStatus').append(type + ": " + status + '<br /><br />');
},
onSave: function(data) {
$.ajax({
type: "POST",
url: pageUrl + "/GetCapturedImage",
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(r) {
$("[id*=imgCapture]").css("visibility", "visible");
$("[id*=imgCapture]").attr("src", r.d);
},
failure: function(response) {
alert(response.d);
}
});
},
onCapture: function() {
webcam.save(pageUrl);
}
});
});
function Capture() {
webcam.capture();
return false;
}
function pageLoad(sender, args) {
if (args.get_isPartialLoad()) {
var pageUrl = '<%=ResolveUrl("~/frmVisitasPorSetor.aspx") %>';
$(function() {
jQuery("#webcam").webcam({
width: 220,
height: 165,
mode: "save",
swffile: '<%=ResolveUrl("~/App_Themes/Webcam_Plugin/jscam.swf") %>',
debug: function(type, status) {
// $('#camStatus').append(type + ": " + status + '<br /><br />');
},
onSave: function(data) {
$.ajax({
type: "POST",
url: pageUrl + "/GetCapturedImage",
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(r) {
$("[id*=imgCapture]").css("visibility", "visible");
$("[id*=imgCapture]").attr("src", r.d);
},
failure: function(response) {
alert(response.d);
}
});
},
onCapture: function() {
webcam.save(pageUrl);
}
});
});
function Capture() {
webcam.capture();
return false;
}
}
}