TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Deon Gee
NA
4
8.8k
Pass varible from one page to another ASP.Net VB
Aug 30 2012 3:21 PM
I would like to pass the PubDate from Test.aspx to Test2.aspx
(Test Page 1) test.aspx.vb
Dim
con
As
New
SqlConnection
(
"Data Source=MyDB;Initial Catalog=Me;User ID=MyAdmin;Password=MyPswd"
)
'Declare values from user input
Dim
fileName
As
String
=
""
Dim
FilePath
As
String
=
Path
.GetFileName(fileName)
Dim
Title
As
String
= txtTitle.Text.ToString()
Dim
Title2
As
String
= txtTitle2.Text.ToString()
Dim
City
As
String
= txtCity.Text.ToString()
Dim
State
As
String
= txtState.Text.ToString()
Dim
PubDate
As
String
= txtPubdate.Text.ToString()
Dim
Description
As
String
= txtDescription.Content.ToString()
lblSuccess.Text =
""
txtTitle.Text =
""
txtTitle2.Text =
""
txtCity.Text =
""
txtState.Text =
""
txtPubdate.Text =
""
txtDescription.Content =
""
'PubDate = Request.QueryString("PubDate")
Dim
cmd
As
New
SqlCommand
()
cmd.Connection =
Nothing
cmd.CommandText =
"INSERT INTO NewsroomTestimony(Title, Title2, City, State, PubDate, Description, FileName) values(@Title,@Title2,@City,@State,@PubDate,@Description,@FileName)"
cmd.Parameters.AddWithValue(
"@Title"
, Title)
cmd.Parameters.AddWithValue(
"@Title2"
, Title2)
cmd.Parameters.AddWithValue(
"@City"
, City)
cmd.Parameters.AddWithValue(
"@State"
, State)
cmd.Parameters.AddWithValue(
"@PubDate"
, PubDate)
cmd.Parameters.AddWithValue(
"@Description"
, Description)
cmd.Parameters.AddWithValue(
"@FileName"
,
"../newsroom/testimonyInfo/"
& FilePath)
cmd.Connection = con
con.Open()
Dim
result
As
Integer
= cmd.ExecuteNonQuery()
con.Close()
Response.Clear()
If
result > 0
Then
lblSuccess.Text =
"Testimony Created"
Response.Write(PubDate)
End
If
End
Sub
(Test Page 2) test2.aspx.vb
Protected
Sub
Page_Load(sender
As
Object
, e
As
EventArgs
)
If
Not
IsPostBack
Then
Dim
con
As
New
SqlConnection
(
"Data Source=HQDANA3A413VDB1;Initial Catalog=Sigar;User ID=Sigar_Admin;Password=$Jzpoj^6z>%y9E"
)
Dim
cmd
As
New
SqlCommand
()
Dim
queryString
As
String
=
"SELECT PubDate FROM NewsroomTestimony"
cmd.Connection =
Nothing
cmd.CommandText = queryString
cmd.Connection = con
Dim
dr
As
SqlDataReader
con.Open()
dr = cmd.ExecuteReader()
txtPubdate.Text =
"PubDate"
txtPubdate.DataBind()
dr.Close()
con.Close()
End
If
End
Sub
Protected
Sub
SubmitBtn_Click(sender
As
Object
, e
As
System.
EventArgs
)
Dim
con
As
New
SqlConnection
(
"Data Source=MyDB;Initial Catalog=Me;User ID=MyAdmin;Password=MyPswd"
)
Dim
queryString
As
String
=
"SELECT * FROM NewsroomTestimony where PubDate='"
+ txtPubdate.Text &
"'"
Dim
fileName
As
String
=
""
Try
Dim
cmd
As
New
SqlCommand
()
cmd.Connection =
Nothing
cmd.CommandText = queryString
cmd.Connection = con
Dim
dr
As
SqlDataReader
con.Open()
dr = cmd.ExecuteReader()
Dim
settings
As
New
XmlWriterSettings
()
settings.Indent =
True
Dim
writer
As
XmlWriter
=
XmlWriter
.Create(Server.MapPath(
"TestimonyDetail.xml"
), settings)
writer.WriteStartDocument()
writer.WriteStartElement(
"newsroom"
)
writer.WriteStartElement(
"testimony"
)
While
dr.Read()
writer.WriteStartElement(
"detail"
)
writer.WriteElementString(
"title"
, dr.GetString(dr.GetOrdinal(
"Title"
)))
writer.WriteElementString(
"subtitle"
, dr.GetString(dr.GetOrdinal(
"Title2"
)))
Dim
dateNew
As
String
=
""
, monthNew
As
String
=
""
, strTime
As
String
=
""
Dim
sCity
As
String
= dr.GetString(dr.GetOrdinal(
"City"
))
Dim
sState
As
String
= dr.GetString(dr.GetOrdinal(
"State"
))
Dim
DTNew
As
DateTime
DTNew = dr.GetDateTime(dr.GetOrdinal(
"PubDate"
))
dateNew = DTNew.ToLongDateString()
sCity = sCity &
", "
& sState &
" ~ "
& dateNew
monthNew = DTNew.ToString(
"yyyy-MMM-dd"
).ToLower()
Dim
nowTime
As
DateTime
=
DateTime
.Now
strTime = nowTime.Millisecond.ToString(
""
)
'Create the folder by year
' Dim NewFolderYear = ""
' Dim yearNew As String = ""
' Dim basePath As String = Server.MapPath("../TestimonyDetail/")
'yearNew = DTNew.ToString("yyyy").ToUpper()
'Directory.CreateDirectory(Path.Combine(basePath, yearNew))
fileName = monthNew &
"-ig-testify-"
& strTime &
".html"
writer.WriteElementString(
"location_date"
, sCity)
writer.WriteElementString(
"description"
, dr.GetString(dr.GetOrdinal(
"Description"
)))
writer.WriteEndElement()
End
While
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Flush()
writer.Close()
dr.Close()
Catch
ex
As
Exception
Response.Write(ex.Message)
Return
Finally
con.Close()
End
Try
'check for folder year ex: 2012
Dim
sourceFile
As
String
= Server.MapPath(
"testimonyDetail.xml"
)
Dim
stylesheet
As
String
= Server.MapPath(
"testimonyDetail.xsl"
)
Dim
outputFile
As
String
= Server.MapPath(fileName)
Dim
xslt
As
New
XslCompiledTransform
(
True
)
xslt.Load(stylesheet)
Dim
outputStream
As
New
FileStream
(outputFile,
FileMode
.Append)
xslt.Transform(sourceFile,
Nothing
, outputStream)
lblSuccess.Text =
"XML & HTML Done!"
Response.Write(outputFile)
End
Sub
Reply
Answers (
0
)
What is Polymorphism?
What are the uses of SiteMapPathControl ,SiteMapProvider , SiteMapDataSource Control and their differences?