Transfer Javascript string to codebehind

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
 
L

Leon Mayne

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
 
M

Michael Bohman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top