Click here to Skip to main content
15,911,646 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: User authenitcation using a database Pin
Paul Conrad28-Jul-07 18:58
professionalPaul Conrad28-Jul-07 18:58 
GeneralRe: User authenitcation using a database Pin
ASPnoob28-Jul-07 19:17
ASPnoob28-Jul-07 19:17 
GeneralRe: User authenitcation using a database Pin
Paul Conrad28-Jul-07 19:26
professionalPaul Conrad28-Jul-07 19:26 
GeneralRe: User authenitcation using a database [modified] Pin
ASPnoob28-Jul-07 20:04
ASPnoob28-Jul-07 20:04 
GeneralRe: User authenitcation using a database Pin
Paul Conrad28-Jul-07 20:17
professionalPaul Conrad28-Jul-07 20:17 
QuestionRSS FEED Pin
Sarfaraj Ahmed28-Jul-07 16:45
Sarfaraj Ahmed28-Jul-07 16:45 
QuestionAdding header footer usercontrols [modified] Pin
TheEagle28-Jul-07 14:04
TheEagle28-Jul-07 14:04 
Questionadding and removing table rows dynamically [modified] Pin
jojoStoneHead28-Jul-07 7:14
jojoStoneHead28-Jul-07 7:14 
I have been trying to create a user control that allows users to add and remove emails from their profiles and I havent been able to wrap my head around ViewState and Postbacks.

When the profile page is loaded there is one table row with 3 cells:
cell(0) contains two imagebuttons, one to add a new row and another to delete that particular row.
cell(1) contains a label
cell(2) contains a textbox to add the email

I want the user to click the add imagebutton to add a new row and the delete imagebutton to delete that particular row.

My problem is I cant seem to be able to add more than 2 rows. And if I click the buttons in the second row I don't seem to hit Click event handler for the clicked button.

Here is the code:
----------------------------------------------------
Imports System.Configuration
Public Class UC_Emails
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
End Sub

Protected WithEvents plcEmailTable As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents tblUserEmails As System.Web.UI.WebControls.Table


'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
AddEmailRow(maxEmails)
End Sub

#End Region

Dim maxEmails As Integer = CInt(ConfigurationSettings.AppSettings("MaxEmails"))

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
plcEmailTable.Controls.Add(tblUserEmails)
End Sub

Private Sub AddEmailRow(ByVal maxrows As Short)
If Not tblUserEmails.Rows.Count > maxrows Then
Dim eRow As New TableRow
'cells
Dim imgCell As New TableCell
Dim lblCell As New TableCell
Dim txtCell As New TableCell
Dim chkCell As New TableCell
'plus imagebutton
Dim plusImg As New ImageButton
plusImg.CssClass = "PlusMinusImage"
plusImg.ImageUrl = CType(Session("imagespath"), String).Replace(".", "~") & _
"btn_plus.jpg"
AddHandler plusImg.Click, AddressOf btnAdd_Click
'minus imagebutton
Dim minusImg As New ImageButton
minusImg.CssClass = "PlusMinusImage"
minusImg.ImageUrl = CType(Session("imagespath"), String).Replace(".", "~") & _
"btn_minus.jpg"
AddHandler minusImg.Click, AddressOf btnDelete_Click
'label
Dim lblEmail As New Label
lblEmail.Text = "Email:"
'text box
Dim txtEmail As New TextBox
txtEmail.CssClass = "EmailTextBox"
'primary check box
Dim chkPrimary As New CheckBox
chkPrimary.Text = "Primary email"
'add itrems to cells
imgCell.Controls.Add(plusImg)
imgCell.Controls.Add(minusImg)
lblCell.Controls.Add(lblEmail)
txtCell.Controls.Add(txtEmail)
chkCell.Controls.Add(chkPrimary)
'add cells to row
eRow.Cells.Add(imgCell)
eRow.Cells.Add(lblCell)
eRow.Cells.Add(txtCell)
eRow.Cells.Add(chkCell)
tblUserEmails.Rows.Add(eRow)
End If
End Sub

Private Sub DeleteEmailRow(ByVal sender As Object, ByVal remaminingRows As Integer)
If Not tblUserEmails.Rows.Count = 1 Then
Dim btnClicked As ImageButton = CType(sender, System.Web.UI.WebControls.ImageButton)
Dim row As TableRow
Dim cell As TableCell
cell = CType(btnClicked.Parent, TableCell)
row = cell.Parent
tblUserEmails.Rows.Remove(row)
End If
End Sub

Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
AddEmailRow(maxEmails)
End Sub

Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
DeleteEmailRow(sender, tblUserEmails.Rows.Count)
End Sub

End Class
----------------------------------------------------------------


Please help in pointing out where I'm getting it wrong



-- modified at 13:21 Saturday 28th July, 2007
AnswerRe: adding and removing table rows dynamically [modified] Pin
wk63328-Jul-07 7:29
wk63328-Jul-07 7:29 
QuestionRe: adding and removing table rows dynamically Pin
jojoStoneHead28-Jul-07 8:14
jojoStoneHead28-Jul-07 8:14 
AnswerRe: adding and removing table rows dynamically Pin
wk63328-Jul-07 10:49
wk63328-Jul-07 10:49 
GeneralRe: adding and removing table rows dynamically Pin
jojoStoneHead28-Jul-07 11:09
jojoStoneHead28-Jul-07 11:09 
QuestionControl Type Pin
hadad28-Jul-07 4:50
hadad28-Jul-07 4:50 
AnswerRe: Control Type Pin
Guffa28-Jul-07 10:01
Guffa28-Jul-07 10:01 
QuestionRunning Videos Pin
.NET- India 28-Jul-07 3:01
.NET- India 28-Jul-07 3:01 
QuestionAsychronous call to URL behind the scene without redirecting to the page Pin
Amvir28-Jul-07 2:39
Amvir28-Jul-07 2:39 
AnswerRe: Asychronous call to URL behind the scene without redirecting to the page Pin
Brady Kelly28-Jul-07 5:54
Brady Kelly28-Jul-07 5:54 
GeneralRe: Asychronous call to URL behind the scene without redirecting to the page Pin
Amvir29-Jul-07 20:25
Amvir29-Jul-07 20:25 
GeneralRe: Asychronous call to URL behind the scene without redirecting to the page Pin
Brady Kelly29-Jul-07 21:51
Brady Kelly29-Jul-07 21:51 
QuestionHyperlink and AJAX ModalPopup Pin
h@s@n28-Jul-07 2:15
h@s@n28-Jul-07 2:15 
QuestionColor html document Printing Pin
rahul21nov28-Jul-07 2:06
rahul21nov28-Jul-07 2:06 
AnswerRe: Color html document Printing Pin
Blue_Boy28-Jul-07 2:15
Blue_Boy28-Jul-07 2:15 
QuestionReteriving data from database Pin
h@s@n28-Jul-07 2:06
h@s@n28-Jul-07 2:06 
QuestionMaster Page Problem Pin
Mahesh.J28-Jul-07 1:08
Mahesh.J28-Jul-07 1:08 
AnswerRe: Master Page Problem [modified] Pin
wk63328-Jul-07 6:30
wk63328-Jul-07 6:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.