0

I'm creating a User Control for a quick form. This need needs to store data in two places: one is a custom built (by someone else) database that uses JavaScript to submit the data, and the other is a CRM that uses .NET APIs to submit data.

My form currently submit the JavaScript side without problem, but I cannot get any .NET code to run.

An example of my code is:

nps.ascx

<html>
<head>
<script type='text/javascript'>
function doSubmit() {
  SubmitJavaScriptBasedData('title','stuff',$['[id$=comment]').val());
  $('[id$=comment].css('visibility','hidden');
  return true;
}
</script>
</head>
<body>
<asp:RadioButton ID="RB1" GroupName="Buttons" runat="server" /><br />
<asp:RadioButton ID="RB2" GroupName="Buttons" runat="server" /><br />
<asp:RadioButton ID="RB3" GroupName="Buttons" runat="server" /><br />
<asp:RadioButton ID="RB4" GroupName="Buttons" runat="server" /><br />
<p>
<asp:TextBox id="comment" runat="server" TextMode="MultiLine"></asp:TextBox>
<p>
<asp:Button id="submitBtn" runat="server" Text="Go!" OnClientClick="doSubmit();" OnClick="submitComment_Click"></asp:Button>
<p>
<asp:Label id="lblTest" runat="server"></asp:Label>
</body>
</html>

nps.ascx.cs:

...
protected void submitComment_Click(object sender, EventArgs e)
{
    lblTest.Text = "Hello World!";
}
...

When I click my button, I get the expected JavaScript things happening: my remote database is updated and the 'comment' textbox disappears. However, no .NET code is executed at all.

Can anyone help me understand why I'm not getting .NET stuff executed?

P.S. I re-wrote this code from memory and as an example - including all the (I think) relevant pieces) - so there may be mistakes during typing. I think the underlying issue, however, is specifically to do with submissions.

QMKevin
  • 1,101
  • 3
  • 13
  • 26
  • possible duplicate of [OnclientClick and OnClick is not working at the same time?](http://stackoverflow.com/questions/2155048/onclientclick-and-onclick-is-not-working-at-the-same-time) – Wiktor Zychla Aug 26 '13 at 20:43

2 Answers2

1

Well, try with this (it's absolutely not a good solution, but it's only to try if it works)

<asp:Button ClientIdMode="Static" id="submitBtn" runat="server" Text="Go!" OnClientClick="doSubmit(); __doPostBack('submitBtn','');" OnClick="submitComment_Click"></asp:Button>
Alessio
  • 2,018
  • 25
  • 26
  • Thanks for posting, but that didn't work. My JavaScript still submitted correctly, but no .NET was executed (I'm writing to a simple plain text file as a test - but no file is created). I'll keep looking - maybe to do with SharePoint/Master pages? Dunno – QMKevin Aug 26 '13 at 22:05
1

Try this set of code.

<asp:Button id="submitBtn" runat="server" Text="Go!" OnClientClick="javascript:return doSubmit();" OnClick="submitComment_Click"></asp:Button>
Robin Joseph
  • 1,210
  • 1
  • 11
  • 12
  • That didn't work either, but I did just try something I should have done in the first place - remove the `onClientClick` leaving just the `onClick` and wow.. that doesn't work on it's own. I'll get that working, then try both the answers for the client-side, and mark appropriately (chronologically if both work). Thanks – QMKevin Aug 27 '13 at 12:18