Results 1 to 6 of 6

Thread: can we pass parameters from codebehind to script

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up 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

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: can we pass parameters from codebehind to script

    Yep. A quick search turned up these:
    http://aspalliance.com/851
    http://forums.asp.net/p/295952/295952.aspx

    Hope they help.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up 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.

  4. #4
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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.

  5. #5
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  6. #6
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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
  •  



Click Here to Expand Forum to Full Width