我无法从隐藏字段中获取代码中的JSignature画布数据

时间:2013-01-30 17:35:48

标签: asp.net html5

我正在使用jSignature捕获用户签名,之后我想把它放到数据库中,我有签名面板显示,当我将数据发送到警报框时我可以看到它,我也有页面中的asp.net隐藏字段是我存储的数据,问题是我无法将数据存入我的代码,因此我可以将其存储在数据库中。

<telerik:RadCodeBlock runat="server">

<script src="../Scripts/JSignature/jquery-1.9.0.min.js"></script>
<script src="../Scripts/JSignature/jSignature.min.js"></script>

<script type="text/javascript">



    function SaveCanvasImage() {

        var image = $('#signature').jSignature('getData', 'base30');
        var hdnField = $('#<%= hdnSignature.ClientID %>');
        $('#<%=btnHidden.ClientID %>').click();
        return false;
    }

</script> 


     <script>
         function pageLoad() {
             InitSignaturePanel(); //this is a function in a global js file.
         }
     </script>  

</telerik:RadCodeBlock>     



<!--[if lt IE 9]>
    <script type="text/javascript" src="../Scripts/JSignature/flashcanvas.js"></script>
    <![endif]-->


<telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
<div class="width400">
  <telerik:RadAjaxPanel runat="server">    <asp:Label runat="server" ID="lblHidden" />
    <asp:HiddenField runat="server" ID="hdnSignature"  />
    <div id="signature" class="trueMargin signaturePanel"></div>
    </telerik:RadAjaxPanel>

    <div class="textAlignCenter">
        <br />
        <input type="button" id="clearCanvas" value="Reset" onclick="$('#signature').jSignature('clear')" />

           <asp:Button  id="btnCaptureCanvas" runat="server" Text="Save and Close" OnClientClick="SaveCanvasImage()"  />
        <asp:Button runat="server" ID="btnHidden"  OnClick="btnHidden_Click" />    

   </div>
 </div>

<telerik:RadCodeBlock runat="server"> <script src="../Scripts/JSignature/jquery-1.9.0.min.js"></script> <script src="../Scripts/JSignature/jSignature.min.js"></script> <script type="text/javascript"> function SaveCanvasImage() { var image = $('#signature').jSignature('getData', 'base30'); var hdnField = $('#<%= hdnSignature.ClientID %>'); $('#<%=btnHidden.ClientID %>').click(); return false; } </script> <script> function pageLoad() { InitSignaturePanel(); //this is a function in a global js file. } </script> </telerik:RadCodeBlock> <!--[if lt IE 9]> <script type="text/javascript" src="../Scripts/JSignature/flashcanvas.js"></script> <![endif]--> <telerik:RadScriptManager runat="server"></telerik:RadScriptManager> <div class="width400"> <telerik:RadAjaxPanel runat="server"> <asp:Label runat="server" ID="lblHidden" /> <asp:HiddenField runat="server" ID="hdnSignature" /> <div id="signature" class="trueMargin signaturePanel"></div> </telerik:RadAjaxPanel> <div class="textAlignCenter"> <br /> <input type="button" id="clearCanvas" value="Reset" onclick="$('#signature').jSignature('clear')" /> <asp:Button id="btnCaptureCanvas" runat="server" Text="Save and Close" OnClientClick="SaveCanvasImage()" /> <asp:Button runat="server" ID="btnHidden" OnClick="btnHidden_Click" /> </div> </div>

在我背后的代码中:

 protected void btnHidden_Click(object sender, EventArgs e)
    {
        lblHidden.Text = hdnSignature.Value;
    }

1 个答案:

答案 0 :(得分:0)

怀疑发生这种情况是因为您实际上没有将签名放入隐藏字段。

我认为你的意思是:

function SaveCanvasImage() {
    var image = $('#signature').jSignature('getData', 'base30');
    var hdnField = $('#<%= hdnSignature.ClientID %>').val('data:' + image.join(',')); // <-- note the addition
    $('#<%=btnHidden.ClientID %>').click(); // <- what is this for by the way? 
    return false;
}