Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, March 29, 2012

passing values between aspx.vb pages

About javascript window.opener. How do I pass values from source.vb to object.vb if I use window.opener("target.aspx") in a javascript function? I want to use a separate .js file for this purpose.

My code looks something like this.

'Source.aspx
<script ... src="http://pics.10026.com/?src=scripts.js"
<a onclick="newwindow()">text</a
'Source.aspx.vb

variable1 as String
variable2 as Integer

'scripts.js
function newwindow() {
myWin = opener("target.aspx");
}

'Target.aspx.vb

variabletarget1 as String
variabletarget2 as Integer

So, I would like to set variabletarget1 = variable1 and variabletarget2 = variable2 in the process. I am not using frames or iframes. MSDN says that window.opener works only in <frame> or <iframe> pages.

How to do this with javascript?

HenrixHi Henrix,
Somethig like this:


'Source.aspx
<script ... src="http://pics.10026.com/?src=scripts.js"
<a runat="server">text</a
'Source.aspx.vb

variable1 as String
variable2 as Integer
...

a.Attributes.Add("onclick", "newwindow('"& variable1 & "'," & variable2 & ")"

'scripts.js
function newwindow(variable1, variable2) {
myWin = opener("target.aspx?variable1="+variable1+"&variable2="+variable2);
}

'Target.aspx.vb

variabletarget1 as String
variabletarget2 as Integer
...
variabletarget1 = Request.QueryString("variable1")
variabletarget2 = Int32.Parse(Request.QueryString("variable2"))

Passing values between client and server side (Javascript to C#)

I would like to access client side values from the code behind.

Say I open a window like this

 popWindow = window.open("data_list.aspx","dataWindow",'toolbar,width=150,height=100')
 How can I get the window name "dataWindow" from that current window or the parent window?
 Any other examples accessing variables between server side (C#) and client side (JavaScript) would be greatly appreciated.
 Regards -WH 

Page.Request.ServerVariables["SCRIPT_NAME"] will get the name of the current page. You can also pass values in a querystring, which will make them accessible to server-side code.
thanks, Page.Request.ServerVariables["SCRIPT_NAME"] worked out for me.

Passing Values By javascript

I have two webforms with the names frm1 and frm2. When user hits a button at
the frm1, frm2 opens in a new window. After clicking one row in frm2, this
form is closing.. But i can't pass the values to the frm1 without
postingback frm1. Is ther anyway to pass the values from one WebForm to
another without postingback especially in Javascript?Yes we can use hidden field for that.
sample code
window.opener.document.getElementById("hdAddedSpots").value += ',' +
songId;
window.opener is frm1 that has a hidden field in the name of
"hdAddedSpots".
thanks,
PB
"Alper OZGUR" <alpozgur@.gmail.com> wrote in message
news:OCwAFiTPGHA.668@.TK2MSFTNGP11.phx.gbl...
>I have two webforms with the names frm1 and frm2. When user hits a button
>at the frm1, frm2 opens in a new window. After clicking one row in frm2,
>this form is closing.. But i can't pass the values to the frm1 without
>postingback frm1. Is ther anyway to pass the values from one WebForm to
>another without postingback especially in Javascript?
>
>
Here's an article with links to five different tutorials on how to do what
you need:
http://www.webdevelopersjournal.com...ass_values.html
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Alper OZGUR" <alpozgur@.gmail.com> wrote in message
news:OCwAFiTPGHA.668@.TK2MSFTNGP11.phx.gbl...
>I have two webforms with the names frm1 and frm2. When user hits a button
>at the frm1, frm2 opens in a new window. After clicking one row in frm2,
>this form is closing.. But i can't pass the values to the frm1 without
>postingback frm1. Is ther anyway to pass the values from one WebForm to
>another without postingback especially in Javascript?
>
>
Lot's of thanks to both of you.
"S. Justin Gengo [MCP]" <justin@.[no_spam_please]aboutfortunate.com>, haber
iletisinde unlar yazd:u7Rj1uTPGHA.1696@.TK2MSFTNGP14.phx.gbl...
> Here's an article with links to five different tutorials on how to do what
> you need:
> http://www.webdevelopersjournal.com...ass_values.html
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Alper OZGUR" <alpozgur@.gmail.com> wrote in message
> news:OCwAFiTPGHA.668@.TK2MSFTNGP11.phx.gbl...
>

Passing Values By javascript

I have two webforms with the names frm1 and frm2. When user hits a button at
the frm1, frm2 opens in a new window. After clicking one row in frm2, this
form is closing.. But i can't pass the values to the frm1 without
postingback frm1. Is ther anyway to pass the values from one WebForm to
another without postingback especially in Javascript?Yes we can use hidden field for that.

sample code
window.opener.document.getElementById("hdAddedSpots").value += ',' +
songId;

window.opener is frm1 that has a hidden field in the name of
"hdAddedSpots".

thanks,
PB

"Alper OZGUR" <alpozgur@.gmail.com> wrote in message
news:OCwAFiTPGHA.668@.TK2MSFTNGP11.phx.gbl...
>I have two webforms with the names frm1 and frm2. When user hits a button
>at the frm1, frm2 opens in a new window. After clicking one row in frm2,
>this form is closing.. But i can't pass the values to the frm1 without
>postingback frm1. Is ther anyway to pass the values from one WebForm to
>another without postingback especially in Javascript?
>
Here's an article with links to five different tutorials on how to do what
you need:

http://www.webdevelopersjournal.com...ass_values.html

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Alper OZGUR" <alpozgur@.gmail.com> wrote in message
news:OCwAFiTPGHA.668@.TK2MSFTNGP11.phx.gbl...
>I have two webforms with the names frm1 and frm2. When user hits a button
>at the frm1, frm2 opens in a new window. After clicking one row in frm2,
>this form is closing.. But i can't pass the values to the frm1 without
>postingback frm1. Is ther anyway to pass the values from one WebForm to
>another without postingback especially in Javascript?
>
Lot's of thanks to both of you.
"S. Justin Gengo [MCP]" <justin@.[no_spam_please]aboutfortunate.com>, haber
iletisinde unlar yazd:u7Rj1uTPGHA.1696@.TK2MSFTNGP14.phx.gbl...
> Here's an article with links to five different tutorials on how to do what
> you need:
> http://www.webdevelopersjournal.com...ass_values.html
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Alper OZGUR" <alpozgur@.gmail.com> wrote in message
> news:OCwAFiTPGHA.668@.TK2MSFTNGP11.phx.gbl...
>>I have two webforms with the names frm1 and frm2. When user hits a button
>>at the frm1, frm2 opens in a new window. After clicking one row in frm2,
>>this form is closing.. But i can't pass the values to the frm1 without
>>postingback frm1. Is ther anyway to pass the values from one WebForm to
>>another without postingback especially in Javascript?
>>
>>
>>
>>

Monday, March 26, 2012

Passing Values to javascript through code behind

Hi All,

I m having one website where i need to show image animation of three images. Daily those three images will be changed based on which client clicks for displaying.

I could fetch the image name from the database. Also i was succesful in uploading the images in ftp via coding. Now i want the image name and image path that is in code behind, to be passed to javascript funtion. This function is for image animation. Right now i have manually given three images name, it runs perfectly.

I would like to know how would i pass the values from code behind to aspx page in javascript function.

Please help.

Thanks :)it is easy to pass the value from codebehid to javascript

test it
first thing u have to do is make the variable is public which u want to use at javascript
and code the following
Code behid value is <%#CODEBEHINDVAR %>

OR

just click IT

http://forums.asp.net/p/930587/1090409.aspx

regards,
koolprasad2003:)
Thanks !

I'ill try and let u know...if i could do it or not. Many places i saw Page.RegisterClientScript . How and where to use this? what's its use?
Page.RegisterClientScriptBlock and Page.RegisterStartupScript are both used from the codebehind to write out bits of javascript to the finally rendered HTML source. This allows you to dynamically generate the javascript. The keyword being dynamic, so you can specify which three images to be displayed using the codebehind.

So all you'll need to do is have your javascript method ready, but use .RegisterClientScriptBlock() to write out the three dynamic values.
hey thanks...it worked.... thanks once again

passing variable from code behind to function in javascript

Just wondering if someone could provide an example of passing a variable from
the code behind to javascript in vb. I want to have one control have focus
with the page loading with one condition and have another control with focus
after the page loads from a different condition. A gets set in the code
aspx.vb file and the script might look something like,
<script language="javascript">
function DoHighlight(a)
{
if a = 1 {
document.Form1.dr_lst_system.focus();
}
else
{
Form1.textbox1.focus();
}
}
</script
thanks.
--
Paul G
Software engineer.Hi Paul,

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
..Net Developer
Ambiguity has a certain quality to it.

"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:1BB64CF9-9547-4DF0-9556-E2F88CE79ECA@.microsoft.com...
> Just wondering if someone could provide an example of passing a variable
> from
> the code behind to javascript in vb. I want to have one control have
> focus
> with the page loading with one condition and have another control with
> focus
> after the page loads from a different condition. A gets set in the code
> aspx.vb file and the script might look something like,
> <script language="javascript">
> function DoHighlight(a)
> {
> if a = 1 {
> document.Form1.dr_lst_system.focus();
> }
> else
> {
> Form1.textbox1.focus();
> }
> }
> </script>
>
> thanks.
> --
> Paul G
> Software engineer.
Paul,

This is normally done with hidden input controls. Put a line

<input type=hidden runat=server id=inhA
in the .aspx file. If you switch from Html view to Design and back, you will
find in the code-behind a definition for inhA as an obyect of type
System.Web.UI.HtmlControls.HtmlInputHidden.

You can now set inhA.Value="1" on server side and check if (inhA.value ==
"1") on client side.

Eliyahu

"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:1BB64CF9-9547-4DF0-9556-E2F88CE79ECA@.microsoft.com...
> Just wondering if someone could provide an example of passing a variable
from
> the code behind to javascript in vb. I want to have one control have
focus
> with the page loading with one condition and have another control with
focus
> after the page loads from a different condition. A gets set in the code
> aspx.vb file and the script might look something like,
> <script language="javascript">
> function DoHighlight(a)
> {
> if a = 1 {
> document.Form1.dr_lst_system.focus();
> }
> else
> {
> Form1.textbox1.focus();
> }
> }
> </script>
>
> thanks.
> --
> Paul G
> Software engineer.
Hi thanks for the response. Here is what I have but it does not seem to be
working. In the Java script I have
<form id="Form1" method="post" runat="server">
<input type="hidden" runat="server" id="inhA" NAME="inhA">
<script language="javascript" event="onload" for="window">
if (inhA.value == 0)
{Form1.dr_tx_names.focus();}
if (inhA.value == 1)
{Form1.dr_lst_system.focus();}
</script>and in the aspx.vb file I have
in page load event
If Not Page.IsPostBack Then 'only first time page loads
Me.inhA.Value = 0
and in a dropdown event select-causes the page to reload I have
Me.inhA.Value = 1
**************so I want one control two have focus if inhA = 0 and the other
to have focus if inhA = 1.
thanks for the information.
--
Paul G
Software engineer.

"Eliyahu Goldin" wrote:

> Paul,
> This is normally done with hidden input controls. Put a line
> <input type=hidden runat=server id=inhA>
> in the .aspx file. If you switch from Html view to Design and back, you will
> find in the code-behind a definition for inhA as an obyect of type
> System.Web.UI.HtmlControls.HtmlInputHidden.
> You can now set inhA.Value="1" on server side and check if (inhA.value ==
> "1") on client side.
> Eliyahu
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:1BB64CF9-9547-4DF0-9556-E2F88CE79ECA@.microsoft.com...
> > Just wondering if someone could provide an example of passing a variable
> from
> > the code behind to javascript in vb. I want to have one control have
> focus
> > with the page loading with one condition and have another control with
> focus
> > after the page loads from a different condition. A gets set in the code
> > aspx.vb file and the script might look something like,
> > <script language="javascript">
> > function DoHighlight(a)
> > {
> > if a = 1 {
> > document.Form1.dr_lst_system.focus();
> > }
> > else
> > {
> > Form1.textbox1.focus();
> > }
> > }
> > </script>
> > thanks.
> > --
> > Paul G
> > Software engineer.
>
On Wed, 29 Jun 2005 11:02:04 -0700, Paul wrote:

> Just wondering if someone could provide an example of passing a variable from
> the code behind to javascript in vb. I want to have one control have focus
> with the page loading with one condition and have another control with focus
> after the page loads from a different condition. A gets set in the code
> aspx.vb file and the script might look something like,
> <script language="javascript">
> function DoHighlight(a)
> {
> if a = 1 {
> document.Form1.dr_lst_system.focus();
> }
> else
> {
> Form1.textbox1.focus();
> }
> }
> </script>
>
> thanks.
Something like
if(<%=a%> = 1) will work (a is a server-side variable)
ok thanks for the information.
--
Paul G
Software engineer.

"intrader" wrote:

> On Wed, 29 Jun 2005 11:02:04 -0700, Paul wrote:
> > Just wondering if someone could provide an example of passing a variable from
> > the code behind to javascript in vb. I want to have one control have focus
> > with the page loading with one condition and have another control with focus
> > after the page loads from a different condition. A gets set in the code
> > aspx.vb file and the script might look something like,
> > <script language="javascript">
> > function DoHighlight(a)
> > {
> > if a = 1 {
> > document.Form1.dr_lst_system.focus();
> > }
> > else
> > {
> > Form1.textbox1.focus();
> > }
> > }
> > </script>
> > thanks.
> Something like
> if(<%=a%> = 1) will work (a is a server-side variable)

Saturday, March 24, 2012

passing variables from javascript to ASP code

Hi there,

I was wondering if anyone can tell me a way of passing variables through a javascript function, to a visual basic function, by any means.

However I would like to be able to do this without reloading the page, for aesthetics sakes

cheers Neilhello:

You can't pass javascript variables to ASP functions. The ASP functions run server-side and have completed their execution once the page has loaded and the javascript is ready to be run.

Also, you might do the following:

It's easy to use the value of a VBScript variable in java_script_:
document.writeln('<%= MyVBScriptVariable %>');

Or here is an example which puts the value of a VBScript variable into a JavaScript alert box:
Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable & "');</script>"

But to send the value of a JavaScript variable to VBScript, well that's another story. You could have the JavaScript fill in a hidden form field and then post the form. That way VBScript can pick up the value of the hidden form field with Request.Form("MyFieldName").

try any of these.

regards !!!!
Depending on what your application needs to do with the variables, you could use an IFRAME and have the javascript function submit a form or call a url with a querystring in the IFRAME. Resulting page can return any results you need to use to update client side controls on your page.

Also, if your pages are taking too long to load on postbacks make sure you have SmartNavigation set to true in your page.

Hope this helps.
Hello!

You can use Web services from JavaScript, so write a Web service(th actual function on VB) and call it from JavaScript with parameter you want to pass to VB function.

Hope this helps
I'm not sure of the specifics of what you are trying to do, but to pass strings to code-behind functions, all you have to do is set the html web controls to runat=server. For instance, we use a javascript popup window(widow.open(page.html,windowname,location)) to retrieve comments on our aspx pages. We use a hidden form control(set runat=server) to retrieve the information when the page is posted back. Of course this probably won't fit your need, but you can do it.
in the end i put variables into a js function call in a template on a datalist, then saved the variable in a cookie, which I then requested from the vb code.

thanks for the help though i will look at this post later to take it in properly :)

passing variables from vb.net to javascript

hi is there any way to pass a variable from vb.net to javascript? and something other than putting a hidden label on the page and also without using cookies...
...thank u

elenaHi Elena,

asp.net (vb.net is the language that you can write it with) is a server side technology and javascript is a client side one. But you can pass data.

In the html part place a literal control where you want the variable data to appear when it's rendered. In code-behind you fill up the Text property of the literal control.

Grz, Kris.