Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 30th, 2008, 10:04 AM
Authorized User
 
Join Date: Sep 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to save <asp:placeholder> value

Hi,

I dynamically create a Text Box with two properties and display it in a placeholder (as shown in a code given below).

Default.aspx

<asp : PlaceHolder runat="server" ID="p_holder"></asp : PlaceHolder>

Default.aspx.vb

Dim TBox As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox

p_holder.Controls.Add(TBox)

TBox.ID = "T_ID"
TBox.Text = ""

My Question is how I save the user input for this Text Box, which will available for later use ( means after navigation with different pages)



 
Old September 30th, 2008, 10:36 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

you can save them it to a session variable or you could use properties... there are a couple ways to do it.

Jason Hall
 
Old September 30th, 2008, 11:05 AM
Authorized User
 
Join Date: Sep 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

could you please explain your answers in details

 
Old September 30th, 2008, 11:09 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

post more code and i can give you more details... why are you creating a text box in the place holder dynamically? why not just build it on the page?

Jason Hall
 
Old October 2nd, 2008, 07:00 AM
Authorized User
 
Join Date: Sep 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by alliancejhall
 post more code and i can give you more details... why are you creating a text box in the place holder dynamically? why not just build it on the page?

Jason Hall
Hi

Here is a code for you, First is XML file which is my input, second is aspx.vb code to handel this XML for display

<?xml version="1.0" standalone="yes"?>
<OpeningFileDataset>
<TEXT_BOX>
    <TBLeft>200</TBLeft>
    <TBTop>700</TBTop>
    <TBHeight>25</TBHeight>
    <TBWidth>200</TBWidth>
    <TBContents>"all my values are dynamic"</TBContents>
    <PageNo>1</PageNo>
  </TEXT_BOX>
</OpeningFileDataset>

aspx.vb code

Partial Class Main
    Inherits System.Web.UI.Page

Public TBox As TextBox = New TextBox

Protected Overrides Sub OnInit(ByVal e As EventArgs)

        Dim ds As Data.DataSet = New Data.DataSet()
        Dim filePath As String = Server.MapPath("~/App_Data/My.XML")
        ds.ReadXml(filePath)

       For tcount = 0 To (ds.Tables.Count) - 1

          Select Case (ds.Tables(tcount).TableName)

               Case "TEXT_BOX"
          For Each dr As Data.DataRow In ds.Tables("TEXT_BOX").Rows

                        p_holder.Controls.Add(rtfTxtBox)

         TBox.ID = dr("TBLeft").ToString + dr("TBTop").ToString
                        TBox .Style.Add("left", dr("TBLeft").ToString + "px")
                        rtfTxtBox.Style.Add("top", dr("TBTop").ToString + "px")
                        rtfTxtBox.Height = dr("TBHeight").ToString
                        rtfTxtBox.Width = dr("TBWidth").ToString

                    Next

            End Select
        Next

 End Sub

End Class



as you see the number of text boxs with their properties are not dynamic.

I think it what you ask


Thanks

 
Old October 2nd, 2008, 07:09 AM
Authorized User
 
Join Date: Sep 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dhumplopoka
 
Quote:
quote:Originally posted by alliancejhall
Quote:
 post more code and i can give you more details... why are you creating a text box in the place holder dynamically? why not just build it on the page?

Jason Hall
Hi

Here is a code for you, First is XML file which is my input, second is aspx.vb code to handel this XML for display

<?xml version="1.0" standalone="yes"?>
<OpeningFileDataset>
<TEXT_BOX>
    <TBLeft>200</TBLeft>
    <TBTop>700</TBTop>
    <TBHeight>25</TBHeight>
    <TBWidth>200</TBWidth>
    <TBContents>"all my values are dynamic"</TBContents>
    <PageNo>1</PageNo>
</TEXT_BOX>
</OpeningFileDataset>

aspx.vb code

Partial Class Main
    Inherits System.Web.UI.Page

Public TBox As TextBox = New TextBox

Protected Overrides Sub OnInit(ByVal e As EventArgs)

        Dim ds As Data.DataSet = New Data.DataSet()
        Dim filePath As String = Server.MapPath("~/App_Data/My.XML")
        ds.ReadXml(filePath)

     For tcount = 0 To (ds.Tables.Count) - 1

         Select Case (ds.Tables(tcount).TableName)

             Case "TEXT_BOX"
         For Each dr As Data.DataRow In ds.Tables("TEXT_BOX").Rows

                        p_holder.Controls.Add(rtfTxtBox)

         TBox.ID = dr("TBLeft").ToString + dr("TBTop").ToString
                        TBox .Style.Add("left", dr("TBLeft").ToString + "px")
                        rtfTxtBox.Style.Add("top", dr("TBTop").ToString + "px")
                        rtfTxtBox.Height = dr("TBHeight").ToString
                        rtfTxtBox.Width = dr("TBWidth").ToString

                    Next
        
            End Select
        Next
    
End Sub

End Class



as you see the number of text boxs with their properties are not dynamic.

I think it what you ask


Thanks

please consider "rtfTxtBox" as a "TBox", its my typing error

 
Old October 2nd, 2008, 07:54 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

I'm assuming you are using a linkbutton or button to navigate from page to page?

If so you can do something like this:

Code:
    Protected Sub btnNavigate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNavigate.Click

        Dim txt As TextBox
        Dim Delimiter As String = ""
        For Each con As Control In PlaceHolder1.Controls
            If TypeOf con Is TextBox Then
                txt = New TextBox
                txt = CType(con, TextBox).Text
                If Not String.IsNullOrEmpty(txt) Then
                    Session("TextValues") = Session("TextValues") & Delimiter & txt
                    Delimiter = "~"
                End If
            End If
        Next

    End Sub
Ok what i am doing is, Assuming you are using a button of some kind(I'm calling mine btnNavigate), On button click i'm looping through all the controls in PlaceHolder1 and if it's a text box i'm grabbing it's text value then checking if it has a value. if it has a value i'm adding it to a session variable which you will need to create in the glabal.asa file. Now you will have one session variable that holds all the values of these text boxes which you can use later by splitting it. If you need to know which text box holds what value you can use another delimiter to separate those. I'm sure some one else has a better way but this is JUST AN EXAMPLE... let me know if you need any help with this as it is UNTESTED.

Jason Hall
 
Old October 8th, 2008, 10:53 AM
Authorized User
 
Join Date: Sep 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jason,

Many Thanks, the code work fine with little adjustment, Another problem which I faced now is, I need to store the responses of user using images, For this I used java script but it not work,

<?xml version="1.0" standalone="yes"?>
<PICTURE_BOX>
    <PBTop>544</PBTop>
    <PBHeight>150</PBHeight>
    <PBWidth>200</PBWidth>
</PICTURE_BOX>

ASPX.VB

Public Image1 As System.Web.UI.WebControls.Image = New System.Web.UI.WebControls.Image()

Protected Overrides Sub OnInit(ByVal e As EventArgs)

   Dim ds As Data.DataSet = New Data.DataSet()
   Dim filePath As String = Server.MapPath("~/App_Data/My.XML")
   ds.ReadXml(filePath)

   For tcount = 0 To (ds.Tables.Count) - 1
     Select Case (ds.Tables(tcount).TableName)
        Case " PICTURE_BOX "
          For Each dr As Data.DataRow In ds.Tables("TEXT_BOX").Rows
          ph.Controls.Add(Image1)
          Image1.ID = dr("ABLeft").ToString
          Image1.Style.Add("top", dr("ABTop").ToString + "px")
          Image1.ImageUrl = "~/p.gif"
          Image1.Attributes.Add("name", dr("ABLeft").ToString))

     Image1.Attributes.Add("onclick", "Javascript:click1()")
     Image1.Attributes.Add("ondblclick", "Javascript:click2()")



   End Select
  Next

End Sub

ASPX
<script type="text/javascript" >
    function click1(){document.getElementsById(XXXX).src='blank.gif';}
    function click2(){document.getElementsById(XXXX).src='fill.gif';}
</script>

<html><body><form><div>
<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
</html></body></form></div>

If I hardcode the ID in document.getElementsById its work, My problem is how do I pass the Image ID from .aspx.vb to .aspx wihch used in document.getElementsById and store it.

Thanks in advance
 
Old October 8th, 2008, 10:59 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

If i understand you correctly i think you want something like this:

Image1.Attributes.Add("onclick", "Javascript:click1('" & Image1.ClientID & "')")

<script type="text/javascript" >
    function click1(id1){document.getElementsById(id1).src='bla nk.gif';}
    function click2(id2){document.getElementsById(id2).src='fil l.gif';}
</script>

Jason Hall
 
Old October 8th, 2008, 01:16 PM
Authorized User
 
Join Date: Sep 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I try this but i got error

"Error: Object doesn't support this property or method"

I checked my syntax it ok. Could you please give me any other suggestion

thanks in advance






Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
a problem in book<<beginning asp.net using vb>> luoware ASP.NET 1.0 and 1.1 Basics 3 December 8th, 2003 09:32 PM
HELP HELP ODBC<->ASP <-> XML moon Wrox Book Feedback 1 November 9th, 2003 12:42 PM
<<ASP.NET Security>>,download files in chapter 8 alaix All Other Wrox Books 1 July 24th, 2003 10:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.