Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Learning to use JavaScript with ASP.Net
Message
De
20/05/2009 13:31:02
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
ASP.NET
Application:
Web
Divers
Thread ID:
01400821
Message ID:
01401020
Vues:
38
Thanks Paul,

I just copied this all out to a text file to look at. I got some of this working yesterday but was not able to get a client side script to run after the postback completed. I see some of the answers to this in your post.
Thank You
Tim

>>>Tim
>>
>>I'm working my way through this book right now and it seems to be pretty exhaustive in its coverage.
>>
>>http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996/ref=sr_1_1?ie=UTF8&s=books&qid=1242828609&sr=1-1
>
>Yeah, I've got an older version of this book and it was OK. To be honest, I tend to just Google things now.
>
>To do what you're describing:
>
>
><script language="javascript" type="text/javascript"
>   function SetValue()
>   {
>      var myControl = document.getElementById('txtHidden');
>      if (myControl)
>         document.forms[0].submit();
>        // Instead of this you can use ASP.NET's __doPostback code to fire the postback. If you use it, it's then possible to intercept this info in the page
>        // __doPostBack('ControlOrEventCausingPostback', 'AnyParameters');
>        // In that case, you don't need the hidden input - pass the parameter as the second parameter of __doPostBack
>   }
></script
><input type="hidden" name="txtHidden" /
>
>// In your ASP.NET code-behind:
>if (Page.IsPostBack)
>{
>    string hiddenValue = Request.Form["txtHidden"];
>    // Do something
>    // Or if you are using ASP.NET's __doPostBack you can do this in Page_Load:
>    // string eventName = Request.Form["__EVENTTARGET"];
>    // string arg = Request.Form["__EVENTARGUMENT"];
>    // if (eventName == "ControlOrEventCausingPostback")
>    //    this.DoSomething(arg);
>}
>
>
>
>You can't easily persist variables between postback w/o just recreating them. What I normally do is just inject some JavaScript after the postback which calls the function you want, ex:
>
>
>string script = "<script type=\"text/javascript\">JSFunctionToRun();</script>";
>Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "JustNameOfScript", script);
>// You can actually call RegisterClientScriptBlock with a 4th parameter of true - that will add the <script tag stuff for you.
>
>
>This just tells ASP.NET to inject this JS code into the page. As soon as the browser loads it should run this code.
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform