Setting control text in parent form from modal popup - asp.net

I have a problem I am trying to set the parent textbox from the modal popup.
Although I found the control from the modal popup with the below code
DirectCast(Parent.Page.Form.FindControl("ContentPlaceHolder1").FindControl("myAccordion").FindControl("txtTo"), TextBox).Text = str
This is being called on button click when the user has finished selecting from the Checkboxlist.
When the parent page is shown again though the textbox is empty.
The scenario of my user control is that a user is to select from a checkbox list which is a list of emails.
When done has been clicked then it is required that the selected emails be forwarded to the parent webpage.
Then the To Textbox in this case will be filled with the emails that the user has selected.

You should provide a public property in your UserControl for the selected item in the ListBox. This makes it easy to retrieve(or set) it from the page.
You should also declare an event that you can raise from the ListBox' SelectedIndexChanged event. On this way the page is able to handle this event and set the TextBox' Text accordingly.
For example(in UserControl with ModalPopupExtender):
Public Class PopupControl
Inherits System.Web.UI.UserControl
Public Event ItemChanged(ByVal popup As PopupControl)
Public Property SelectedItem As String
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lb = DirectCast(sender, ListBox)
Me.Visible = False
Me.SelectedItem = lb.SelectedItem.ToString()
RaiseEvent ItemChanged(Me)
End Sub
End Class
In page:
Protected Sub PopupItemChanged(ByVal popup As PopupControl)Handles PopupControl1.ItemChanged
Me.txtTo.Text = popup.SelectedItem
End Sub

Related

How to change BackColor of Button inside a UserControl from another UserControl?

I am using an asp button inside a user control and this user control is in another user control, I want to change the back color of the asp button from second user control,
I have used the below code but the color doesn't change. When I change the button's text using btn.Text this will change, but when I change btn.BackColor this is not working.
Dim btn As Button = DirectCast(ucontrolLetterSelect.FindControl(buttonID), System.Web.UI.WebControls.Button)
btn.BackColor = System.Drawing.Color.Red
You need to create an exposed public property on the user control who's button that you want to change. Then you could set this property through the parent user control.
Exmaple :
I have a user control called TestControl1.ascx
I placed a button called btnTest on this user control
I also created a public property called SetUserControlButtonBackColor in the codebehind of this user control.
Public Property SetUserControlButtonBackColor As Color
Get
Return mColor
End Get
Set(value As Color)
Me.btnTest.BackColor = value
End Set
End Property
I place this user control into my webpage and put a button on my webpage called Button1
On the click event of Button1 I set the public exposed property of my user control which sets the back color of the button within the user control.
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.TestControl1.SetUserControlButtonBackColor = Drawing.Color.Aqua
End Sub
Now when you click the button on your web page it will change the color of your user control

How to pass value from gridview inside modal pop up extender to textbox in parent form?

I tried to execute below codes to pass selected row value from gridview inside modal pop up extender to textbox in parent form but it doesn't work.
Private Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
txttitle.Text = GridView1.SelectedRow.Cells(1).Text
End Sub
Passing values from ajax popup (gridview) to parent page textbox.
This links help you.
http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html
http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html

How to retrieve data from selected row in gridview inside ModalPopUp dialog and then close after in asp.net?

I am trying to retrieve data when selecting a row in gridview using asp.net.
I have gridview inside ModalPopUp dialog that pop-ups whenever the user clicks the button "Browse". The gridview was populated by data from database. The first column was a Button field named "Select", so everytime the user clicks the button from specific row the data on the first index must be displayed inside a textbox, and the ModalPopUp dialog must be closed.
I tried below codes on retrieving the data from selected row and closing or hiding the ModalPopUp dialog after clicking button field inside gridview but it doesn't work.
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Select" Then
Dim row As GridViewRow = GridView1.SelectedRow
txttitle.Text = row.Cells(1).Text
mdlpopup.Hide()
End If
End Sub
Thanks in advance.
Modify your code as like,
txttitle.Text = DirectCast(row.Cells(1).FindControl("TxtboxID"),TextBox).Text

Trigger Anchor Tag with LinkButton onclick function vb.net

as you know, Fancybox comes with the anchor tag
I am currently working on a project of a datalist using vb.net
When I click the Linkbutton, I am suppose to get the command argument and set it to session and then open up the fancybox. As fancybox has its own restriction to anchor tags, it is only workable on the first item of the datalist
So I want to do it in such a way that when I click the linkbutton, I will pass the session and also trigger the anchor tag from the code behind. Here is the codebehind for the button_click for the linkbutton
Protected Sub Button1_Click(sender As Object, e As System.EventArgs)
'Dim addJobRequest As Button = sender
' Dim jobID As String = addJobRequest.CommandArgument
' addJobtoRequest(jobID)
Dim button As LinkButton = sender
Dim itegerr As Integer = button.CommandArgument
Session("jobID") = itegerr
Return
'From here, I need a code that can trigger anchor tag
End Sub
Here is the code for the anchor tag
<a id="fancybox-manual-b" href="javascript:;">
P.s. I have tried the linkbutton href function and but it doesn't work.

Dynamic controls in postback

I'm trying to add a set of LinkButtons to the PagerRow of a GridView in an UpdatePanel. I'm using the RowCreated event to instantiate and add these. The problem I have is the click handlers are only fired the second time.
I create the LinkButtons using
Protected Sub grd_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.Pager) Then
Dim pageSizer = New GridViewPageSizer(grdItems)
e.Row.Cells(0).Controls.AddAt(0, pageSizer)
End If
End Sub
To create the LinkButtons themselves, I'm using
Dim lnkSize = New LinkButton() With { _,
.Text = size.ToString(), _
.CommandArgument = size.ToString(), _
.ID = "pageSizer" & size
}
AddHandler lnkSize.Click, AddressOf lnkPageSize_Click ' an EventHandler which just changes pagesize based on CommandArgument
liSize.Controls.Add(lnkSize)
The GridViewPageSizer inherits HtmlGenericControl and adds an event handler for the click of each button. On every postback, the pager row is recreated, so the old buttons are replaced with a new set and their event handlers only fire on the second click. If I check for !IsPostBack, the buttons disappear after the first click. I've tried rebinding the grid after the buttons are clicked and the pagesize changes but the same thing happens. Is there a way around this?
In order for an EventHandler to trigger correctly, you need to bind it on Page Init/PreInit.
Make a session indicator and on postback, check that session on Page Init.
If that satisfies the condition, instead of recreating it on RowCreated Event, recreate the controls together with the Events on Page Init instead.
This time, events will trigger correctly.

Resources