[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)
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.
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
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.
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
Re: how i can return value string from function javascript to code-behind asp.net
Quote:
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?
Re: how i can return value string from function javascript to code-behind asp.net
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
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
Re: [RESOLVED] how i can return value string from function javascript to code-behind
Re: [RESOLVED] how i can return value string from function javascript to code-behind
Re: [RESOLVED] how i can return value string from function javascript to code-behind
Quote:
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?)
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