|
-
Apr 14th, 2011, 04:40 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] how i can return value string from function javascript to code-behind asp.net
Hi All,
how i can return value string from function javascript to code-behind asp.net
directly as this syntax example but this give me errors
in html code
<script>
function Getstr()
{
return "MyStr";
}
</script>
in code-behind
Page.ClientScript.RegisterStartupScript(Me.Getstr(), "alert", "Getstr();", True)
-
Apr 14th, 2011, 08:42 PM
#2
Re: how i can return value string from function javascript to code-behind asp.net
One way is to make the javascript method set the value of a hidden field control/element then when the page is posted back get the value from the hiddenField.
The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded. 
-
Apr 15th, 2011, 12:09 PM
#3
Thread Starter
Hyperactive Member
Re: how i can return value string from function javascript to code-behind asp.net
thank you very much for reply me
but that is means no other solution expect hidden field control/element
no direct solution
-
Apr 15th, 2011, 08:19 PM
#4
Re: how i can return value string from function javascript to code-behind asp.net
well javascript runs on the client (browser). If you want javascript to communicated with the server you can use ajax but perhaps it would be better to give a broader overview of what you need the page to do.
The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded. 
-
Apr 17th, 2011, 03:05 PM
#5
Thread Starter
Hyperactive Member
Re: how i can return value string from function javascript to code-behind asp.net
thank you for reply
my page aspx include button facebook connection
to give me information like name,age,......about user
by facebook JavaScript API
i want save it in database by make function js return directly value to code-behind
I wish I could find this
-
Apr 18th, 2011, 10:03 AM
#6
Fanatic Member
Re: how i can return value string from function javascript to code-behind asp.net
 Originally Posted by prokhaled
Hi All,
how i can return value string from function javascript to code-behind asp.net
directly as this syntax example but this give me errors
in html code
Code:
<script>
function Getstr()
{
document.getElementById('hfMyStr').value = MyStr;
document.getElementById('btnSubmitString').click();
}
</script>
on the aspx page
Code:
<form id="form1" runat="server">
<asp:HiddenField ID="hfMyStr" runat="server" />
<asp:Button ID="btnSubmitString" runat="server" Height="0" Width="0" OnClick="btnSubmitString_Click" />
</form>
in code-behind
Code:
protected void btnSubmitString_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "myAlert", "alert('" + hfMyStr.Value + "');", true);
What is wrong with brin's suggestion?
-
Apr 18th, 2011, 02:48 PM
#7
Thread Starter
Hyperactive Member
Re: how i can return value string from function javascript to code-behind asp.net
-
Apr 22nd, 2011, 07:02 AM
#8
Re: how i can return value string from function javascript to code-behind asp.net
Hello,
For the benefit of other people who might be reading your thread, you might want to think about telling us what your final solution was.
Gary
-
Apr 22nd, 2011, 05:43 PM
#9
Thread Starter
Hyperactive Member
Re: how i can return value string from function javascript to code-behind asp.net
Code:
For the benefit of other people who might be reading your thread, you might want to think about telling us what your final solution was.
How i can do this i can not remember
-
Apr 22nd, 2011, 05:48 PM
#10
Thread Starter
Hyperactive Member
Re: [RESOLVED] how i can return value string from function javascript to code-behind
-
Apr 23rd, 2011, 09:25 AM
#11
Re: [RESOLVED] how i can return value string from function javascript to code-behind
I'm confused
-
Apr 23rd, 2011, 10:25 AM
#12
Addicted Member
Re: [RESOLVED] how i can return value string from function javascript to code-behind
 Originally Posted by gep13
I'm confused 
Heh. Me too, I opened the thread because I saw it marked as resolved and all I can see is a somewhat funny reply.
Can anyone suggest how do you do what the poster asked?
(other than the solution brin already provided, is there other methods to do it withut a hidden field?)
-
Apr 23rd, 2011, 10:37 AM
#13
Re: [RESOLVED] how i can return value string from function javascript to code-behind
Another solution would be to put the variables onto the QueryString, and inspect the Query String variables on the server.
This isn't a particularly secure way of doing things though. It is better to POST the information to the server, as suggested by Brin, with the use of the HiddenField.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|