By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

Transfer Javascript string to codebehind

P: n/a
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
Mar 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Michael Bohman wrote:
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
Mar 19 '06 #2

P: n/a
Michael,

You can use one of the register script methods, there are more in the Page
class. Have a look at this.

http://msdn.microsoft.com/library/de...blocktopic.asp

I hope this helps,

Cor
"Michael Bohman" <mi************@telia.com> schreef in bericht
news:kQ*******************@newsb.telia.net...
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

Mar 20 '06 #3

P: n/a
Cor Ligthert [MVP] skrev:
Michael,

You can use one of the register script methods, there are more in the Page
class. Have a look at this.

http://msdn.microsoft.com/library/de...blocktopic.asp

I hope this helps,

Cor
"Michael Bohman" <mi************@telia.com> schreef in bericht
news:kQ*******************@newsb.telia.net...
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


Thank's i'll have a look
Mar 20 '06 #4

P: n/a
Leon Mayne skrev:
Michael Bohman wrote:
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

thank's i'll have a look
Mar 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.