|
-
Jul 2nd, 2007, 05:58 AM
#1
Thread Starter
Addicted Member
can we pass parameters from codebehind to script
Hi guys
I have one doubt. We can pass parameters from javascript to asp.net using
callback.Can we pass parameters from asp.net code behind to javascript?
Anyone give example and tell how is possible?
Thanks
Failing to plan is Planning to fail
-
Jul 2nd, 2007, 09:27 AM
#2
Re: can we pass parameters from codebehind to script
-
Jul 2nd, 2007, 09:34 AM
#3
Thread Starter
Addicted Member
Re: can we pass parameters from codebehind to script
Hi buddy,
Thanks to reply.Bcz i am expecting for ur reply.
I saw one article.They told that not possible.I give the link below.
Can we discuss about that?
http://www.velocityreviews.com/forum...avascript.html
Thanks
Fail to plan is Planning to fail.
-
Jul 2nd, 2007, 10:27 AM
#4
Re: can we pass parameters from codebehind to script
I think post #2 in your link explains it well.
It is impossible to pass a variable value from the server to the client.
Server-side code executes on the server. Client-side code executes on the
client.
That said, it is certainly possible to WRITE client-side scripting code
(which will be executed on the client) dynamically from the server side.
That is what you need to do.
--
HTH,
Kevin Spencer
Microsoft MVP
Does that make sense?
And I think that my first link: http://aspalliance.com/851 explains how to write the dynamic JavaScript on the server side.
However, I am not well experienced in this area, so perhaps somebody else can help us both out if there is anything further.
-
Jul 2nd, 2007, 10:52 AM
#5
Re: can we pass parameters from codebehind to script
Yes you can pass parameters from code behind and even control the postback of the page!!
Typo
HTML Code:
function getParamsFromServer(value)
{
if(value == '12345')
{
alert('You entered: " + value + ". Expect PostBack!!');
return true;
}
else
{
alert('You entered: " + value + ". There is now NO PostBack!!');
return false;
}
}
.
.
.
.
<!--html section-->
<asp:Button id="btnPassParams" runat="server" />
Code-behind
Code:
//in the Page_load event
if (!Page.IsPostBack)
{
//in the highlighted part, enter 12345 instead of what is present and see the difference
btnPassParams.Attributes.Add("onclick", "if(getParamsFromServer('asdfsdfsd')) return true; else return false;");
}
Last edited by Harsh Gupta; Jul 2nd, 2007 at 11:38 AM.
-
Jul 2nd, 2007, 08:36 PM
#6
Re: can we pass parameters from codebehind to script
Cool Harsh.
I'm excited to try something like that out.
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
|