Transfer Javascript string to codebehind

  • Thread starter Thread starter Michael Bohman
  • Start date Start date
M

Michael Bohman

Hi

I have a problem, on my page (*.aspx) i have a string written on klients
computer in javascript. How can i pass this string to the codebehind
*.cs file? From there i want to store it to a database...

//Micke
 
Michael said:
I have a problem, on my page (*.aspx) i have a string written on
klients computer in javascript. How can i pass this string to the
codebehind *.cs file? From there i want to store it to a database...

You could create a blank hidden form field and get the javascript to
populate its value before postback, e.g:

<form id="form1" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" />
<input type="submit" name="submit" value="GO" />
<br />
<asp:Literal ID="litResult" runat="server"></asp:Literal></form>
<script language="javascript" type="text/javascript">
<!--
document.form1.HiddenField1.value='Your value';
//-->
</script>

In the code behind file:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Page.IsPostBack = True Then
litResult.Text = HiddenField1.Value
End If
End Sub
 
Leon Mayne skrev:
You could create a blank hidden form field and get the javascript to
populate its value before postback, e.g:

<form id="form1" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" />
<input type="submit" name="submit" value="GO" />
<br />
<asp:Literal ID="litResult" runat="server"></asp:Literal></form>
<script language="javascript" type="text/javascript">
<!--
document.form1.HiddenField1.value='Your value';
//-->
</script>

In the code behind file:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Page.IsPostBack = True Then
litResult.Text = HiddenField1.Value
End If
End Sub
thank's i'll have a look
 
Back
Top