Is there a code behind way of getting at the signature value?
Hi Paul,
We understand that you want to get the Syncfusion EJ Signature value on the server side while clicking the submit button. We would like to let you know that, currently, we do not have a way to get the Signature value on the server side while clicking the submit button.
To achieve your requirement, we have prepared a simple sample of ASP.NET Web Forms with Syncfusion EJ Signature control and manually triggered the Signature upload page method while clicking on the submit button. We have attached the prepared sample for your reference.
Refer to the below code snippet.
[Default.aspx]
<div class="frame "> <h2>Signature:</h2> <div class="control"> <ej:Signature ID="Signature1" Height="400px" StrokeWidth="3" IsResponsive="true" runat="server"></ej:Signature> </div> <br /> <br /> ... <asp:Button ID="Button1" runat="server" Text="submit" OnClientClick="btn1Click();" OnClick="Button1_Click" /><br /><br /><br /> ... <asp:Label ID="userInput" runat="server"></asp:Label> <br /><br /><br /> ... <asp:TextBox id="TextArea1" TextMode="multiline" Columns="50" Rows="5" runat="server" /> </div>
<script> function btn1Click() {
var target = $("#<%=Signature1.ClientID%>").ejSignature("instance")._canvas[0].toDataURL() PageMethods.Upload(target, onSucess, onError);
function onSucess(response) { alert("succesfully sent to datasource") } function onError(response) { alert('Something wrong.'); } } |
[Default.aspx]
public partial class _Default : Page { static string signatureValue { get; set; } ... [System.Web.Services.WebMethod] public static string Upload(string target) { signatureValue = target; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(target); writer.Flush(); stream.Position = 0; SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\support\asp_webform\signature\WebSample677502731\WebSample\App_Data\Signaturedata.mdf;Integrated Security=True;Connect Timeout=30"); // set your system local fle location con.Open(); string query = "INSERT INTO newData (DataValue) VALUES ('" + stream + "')"; SqlCommand cmd = new SqlCommand(query); cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close();
return target; } ... protected void Button1_Click(object sender, EventArgs e) { userInput.Text = UserName.Text; TextArea1.Text = signatureValue; } } } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebSample919771080.zip
Please check the shared sample and get back to us if you need any further assistance.
Regards,
Sivakumar S