Showing posts with label case. Show all posts
Showing posts with label case. Show all posts

Thursday, March 29, 2012

Passing values between 2 open pages (eg. parent and dialog)

Can someone tell me if there is another way of passing variables back and forth between 2 open pages (such as in the case of a dialog window) without using javascript.

I have done it before using javascript but now that I am using a lot of user controls on my pages I find it a pain in the butt with how the user controls are being named, especially when you have multiple nested controls.

Any help would be greatly appreciated.
Thanks.You could use session variables, but this would require that each of the pages involved do a postback in order to be able to read the session variables. Otherwise, javascript is your best bet.
Alright, thanks mendhak, just thought I would check to see if there was a better way.

Saturday, March 24, 2012

Passing variables between pages [CASE CLOSED]

Hi,
I just wanted to know how can i pass my variables from one web page to the other?
For example, I want to pass the server string on the 1st page to other pages. How do i go around doing it?
Pls helpPassing Parameteres from One Page to another (http://aspnet.4guysfromrolla.com/articles/020205-1.aspx)
Thanks a lot Ali. But I don't really understand C#. Is it possible to explain in VB codes? :blush:
Thanks a lot Ali. But I don't really understand C#. Is it possible to explain in VB codes? :blush:
Ok the easiest way to pass data between pages is to use Query String. Suppose you have two variables ([i] firstName and lastName[i]) on Page1 and you want to pass them onto page2, then on Page1 you can build a url like this Dim redirectUrl As String
redirectUrl = "Page2.aspx?firstName=" & firstName & ";&lastName=" & lastName" And then use the redirect method of response like this Response.Redirect(redirectUrl) And in page2 you can access the querystring variables like this Request.QueryString("firstName")

Does this make any sense?
Ideally, connection strings should be held in the web.config file, which looks something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation defaultLanguage="vb" debug="true" />
</system.web>
<appSettings>
<add key="ConnectionInfo" value="server=(local);database=Northwind;Integrated Security=SSPI;uid=sa;pwd=sa;" />
</appSettings>
</configuration>

You need to replace the value of the ConnectionInfo key with your own connection string (and you'll probably want to turn debug off at some point, bearing in mind that the settings in this file apply to all of your pages).

You then retrieve this value in your pages using:
ConfigurationSettings.AppSettings("ConnectionInfo")

However, to just pass the contents of a variable (eg. strForeName = "Jim", strSurname = "Jones"), then you can use the QueryString.

First, when you want to get to the new page, you use:
Response.Redirect("some_page.aspx?forename=" & strForeName & "&surname=" & strSurname)

These variables can then be retrieved in some_page.aspx using this syntax:

Dim strForeName As String = Request.QueryString("forename")
Dim strSurname As String = Request.QueryString("surname")

This can be extended for more variables just by extending the line you use when you redirect to some_page.aspx (eg. "some_page.aspx?var1=value&var2=value&var3=value"). Note the use of the question mark for the first value and ampersand for the following values.
Thanks a lot dude! You really solved my problem.
Greatest thanks to Ali. You're the man! :bigyello: :bigyello: