By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,849 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,849 IT Pros & Developers. It's quick & easy.

How can i get place holder dynamic textbox values

P: 5
Hi all,

i am using place holder for dynamic textbox and label box, then when i enter the values in textbox then i click the add button and save to database, but i couldnt get the dynamic textbox values, Pllssssssssss help how can i get the dynamic values using vb.net

pls help me as soon as possible
regards
kumar

thanxxx....
Aug 13 '08 #1
Share this Question
Share on Google+
9 Replies


yasirmturk
P: 13
Hey dear you have to use ViewState variable for your dynamic controls to keep their values save on postback
Aug 13 '08 #2

P: 5
Hey dear you have to use ViewState variable for your dynamic controls to keep their values save on postback

thanx..

But i am new to vb.net
so i show my code then u will reply me how can i use viewstate

can u help me...
advance thanx...

Expand|Select|Wrap|Line Numbers
  1.  
  2.  Protected Sub BTN_FILTER_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_FILTER.Click
  3.         Dim Hostelname, roomcategory, roomcode As String
  4.         Dim noofseats, totalroom As Integer
  5.         If drp_Hostelname.SelectedIndex = 0 Then
  6.             Hostelname = "%"
  7.         Else
  8.             Hostelname = drp_Hostelname.SelectedItem.Text
  9.         End If
  10.         If drp_Roomcategory.SelectedIndex = 0 Then
  11.             roomcategory = "%"
  12.         Else
  13.             roomcategory = drp_Roomcategory.SelectedItem.Text
  14.         End If
  15.  
  16.         sql_Connect.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConString")
  17.         sql_cmd.CommandText = "SELECT noofseats,totalroom  FROM roomcategory where hostelname='" & Hostelname & "' and roomcategory='" & roomcategory & "'"
  18.         sql_cmd.Connection = sql_Connect
  19.         sql_Connect.Open()
  20.         Dim dr As SqlDataReader
  21.         dr = sql_cmd.ExecuteReader
  22.         dr.Read()
  23.         noofseats = dr(0)
  24.         totalroom = dr(1)
  25.         HOW_MANY = noofseats * totalroom
  26.         dr.Close()
  27.         sql_Connect.Close()
  28.  
  29.  
  30.  
  31.         sql_cmd.CommandText = "SELECT roomcode  FROM roommaster where hostelname='" & Hostelname & "' and roomcategory='" & roomcategory & "'"
  32.         sql_cmd.Connection = sql_Connect
  33.         sql_Connect.Open()
  34.         Dim dr1 As SqlDataReader
  35.         dr1 = sql_cmd.ExecuteReader
  36.         dr1.Read()
  37.         roomcode = dr1(0)
  38.         dr1.Close()
  39.         sql_Connect.Close()
  40.  
  41.         Session("count") = HOW_MANY
  42.         For i = 1 To HOW_MANY
  43.  
  44.             Dim lbl As New Label()
  45.             lbl.ID = "R" & roomcode + i.ToString()
  46.             lbl.Text = lbl.ID
  47.             lbl.CssClass = "aspnetmaker"
  48.             lbl.Width = 60%
  49.  
  50.             add.Controls.Add(lbl)
  51.             If jlbl = 10 Then
  52.                 add.Controls.Add(New LiteralControl("<br>"))
  53.                 jlbl = 0
  54.             End If
  55.  
  56.  
  57.             If jlbl = 0 Then
  58.                 Call newtxt()
  59.             End If
  60.             jlbl = jlbl + 1
  61.  
  62.         Next
  63.  
  64.         add.Controls.Add(New LiteralControl("<br>"))
  65.         For i1 As Integer = 1 To jlbl - 1
  66.  
  67.             Dim txt As New TextBox()
  68.             txt.ID = "txt" + i1.ToString()
  69.             txt.CssClass = "aspnetmaker"
  70.             txt.Text = txt.ID
  71.             txt.Width = 60%
  72.  
  73.             add.Controls.Add(txt)
  74.             txt.Text = ""
  75.         Next
  76.         add.Controls.Add(New LiteralControl("<br>"))
  77.         Dim btn As New Button
  78.         btn.Text = "Save"
  79.         btn.ID = "Btn_Save"
  80.         btn.Attributes("OnClick") = "__doPostBack('" + btn.ID + "'); "
  81.         'AddHandler Me.add.btn.Click, AddressOf btn_Click
  82.         add.Controls.Add(btn)
  83.     End Sub
  84.     Sub newtxt()
  85.         jtxt = 1
  86.         For i1 As Integer = 1 To i
  87.  
  88.             Dim txt As New TextBox()
  89.             txt.ID = "txt" + i1.ToString()
  90.  
  91.             txt.CssClass = "aspnetmaker"
  92.  
  93.             txt.Width = 60%
  94.  
  95.             add.Controls.Add(txt)
  96.  
  97.             If jtxt = 10 Then
  98.                 add.Controls.Add(New LiteralControl("<br>"))
  99.                 jtxt = 0
  100.             End If
  101.  
  102.             If jtxt = 0 Then
  103.                 Exit Sub
  104.             End If
  105.             jtxt = jtxt + 1
  106.         Next
  107.  
  108.  
  109.     End Sub
  110.  
  111.     Protected Sub btn_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  112.  HOW_MANY = Session("count")
  113.         For i As Integer = 0 To HOW_MANY - 1
  114.             Dim txtCtrl As String = "txt" + (i + 1).ToString
  115.             Dim currentControl As Control = Me.FindControl(txtCtrl)
  116.             If TypeOf currentControl Is TextBox Then     '
  117.                 Dim textBoxRef As TextBox = CType(currentControl, TextBox)
  118.  
  119.                 Me.Response.Write((txtCtrl + ": " + textBoxRef.Text + "<br>"))
  120.             End If
  121.         Next
  122.  
  123.  
  124.     End Sub
Aug 13 '08 #3

Curtis Rutland
Expert 2.5K+
P: 3,256
Please use the CODE tags when posting code (the # button on the text editor). Especially when you are going to dump 120 lines of code on us.

MODERATOR
Aug 13 '08 #4

yasirmturk
P: 13
use
Expand|Select|Wrap|Line Numbers
  1. ViewState["USERCONTROLNAME"]= anyinstance;
only one in the code
and re create all the dynamic control on every post back


Hi all,

i am using place holder for dynamic textbox and label box, then when i enter the values in textbox then i click the add button and save to database, but i couldnt get the dynamic textbox values, Pllssssssssss help how can i get the dynamic values using vb.net

pls help me as soon as possible
regards
kumar

thanxxx....
Aug 13 '08 #5

Frinavale
Expert Mod 5K+
P: 9,731
Hi all,

i am using place holder for dynamic textbox and label box, then when i enter the values in textbox then i click the add button and save to database, but i couldnt get the dynamic textbox values, Pllssssssssss help how can i get the dynamic values using vb.net

pls help me as soon as possible
regards
kumar

thanxxx....
Check out how to use dynamic controls in asp.net.

-Frinny
Aug 13 '08 #6

P: 5
use
Expand|Select|Wrap|Line Numbers
  1. ViewState["USERCONTROLNAME"]= anyinstance;
only one in the code
and re create all the dynamic control on every post back

Hi thanx for ur reply,

My requirement is i am getting some values via dropdownlist then create x number of Labels and Text boxes when i am clicking a button. Then i put some values in the textboxes after that i have to show in a label all of the text box values. I am using viewstate but i couldnt get the values... can u help me immediatly for last 4 days i am trying but i couldn't finish..

if i create this code in page init and using view state i can get the values, but i cant use my code in page init because i have to take some values via ddropdownlist then show the textboxes by button clicking event thats why i havent get the view state values i think....

expect your reply..... as soon as possible..
Advance thanx....
Aug 18 '08 #7

P: 5
Check out how to use dynamic controls in asp.net.

-Frinny
Hi

My requirement is i am getting some values via dropdownlist then create x number of Labels and Text boxes when i am clicking a button. Then i put some values in the textboxes after that i have to show in a label all of the text box values. I am using viewstate but i couldnt get the values... can u help me immediatly for last 4 days i am trying but i couldn't finish..

if i create this code in page init and using view state i can get the values, but i cant use my code in page init because i have to take some values via ddropdownlist then show the textboxes by button clicking event thats why i havent get the view state values i think....

expect your reply..... as soon as possible..
Advance thanx....
Aug 18 '08 #8

P: 5
Check out how to use dynamic controls in asp.net.

-Frinny
Hi

My requirement is i am getting some values via dropdownlist then create x number of Labels and Text boxes when i am clicking a button. Then i put some values in the textboxes after that i have to show in a label all of the text box values. I am using viewstate but i couldnt get the values... can u help me immediatly for last 4 days i am trying but i couldn't finish..

if i create this code in page init and using view state i can get the values, but i cant use my code in page init because i have to take some values via ddropdownlist then show the textboxes by button clicking event thats why i havent get the view state values i think....

expect your reply..... as soon as possible..
Advance thanx....
Aug 18 '08 #9

Frinavale
Expert Mod 5K+
P: 9,731
You want to declare your textboxes and labels so that they are global variables for the aspx page. You then want to instantiate these variables in your page_init event. After that point you should be able to access them anywhere in your aspx page.

Please post what you have tried so far.
Sep 5 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.