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

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

Related

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.

How do i use a button inside a loginview

I have added a button inside a loginview, but then this code is not working, do i need some findcontrol like when i have textbox and so on inside a loginview !??
This is not working my loginview have the id="loginview2"
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
Does the < asp:Button in the html have the "btnSave_Click" attached to "Click"?

Setting control text in parent form from modal popup

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

Events Firing Out Of Order Asp.Net

I have a system setup as follows:
User Control Called "Main" when I click a button in "Main" another user control (user control "A", user control "B", user control "C") is populated inside a placeholder of "Main" depending on some logic either A,B, or C is populated.
User controls A,B,C have many buttons on them as well. They Also have a placeholder to contain either user control x, user control y, user control z depending what is clicked inside user control "A" for example.
Main loads controls (A,B, or C) into its placeholder no problem, but when I click a button in A,B,or C to load their placeholder with x,y, or z the whole control (A,B, or C) dissappears.
I understand this has to do with viewstate not holding dynamic controls during a postback. So what I did was explictly called viewstate on the controls loaded into main (A,B,C). when they are loaded I save an entry of what was loaded like this ViewState("lastLoaded")='A' for example. When a postabck occurs (i.e. clicking a button in A) I reload the whole control A.
This is what happens:
I click a button in user control "A"
Postback occurs
User control "A" is reloaded because of the viewstate("lastloaded")
Then I have to click the button in "A" again at that time the button_click event fires
Can someone please help me fix this.
'Here is Main.ascx
Partial Class Main
Inherits System.Web.UI.UserControl
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ViewState("name") = "ControlA2.ascx"
AddControl(ViewState("name").ToString())
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If ViewState("name") <> String.Empty Then
AddControl(ViewState("name").ToString())
End If
End Sub
Public Sub AddControl(ByVal name As String)
PlaceHolder1.Controls.Clear()
Dim toAdd As Control = LoadControl(name)
PlaceHolder1.Controls.Add(toAdd)
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
ViewState("name") = "ControlB.ascx"
AddControl(ViewState("name").ToString())
End Sub
End Class
'Here is Main designer
Main
asp:Button ID="Button1" runat="server" Text="Add Control A"
asp:Button ID="Button2" runat="server" Text="Add Control B"
asp:PlaceHolder ID="PlaceHolder1" runat="server">
'Here is ControlA2.ascx
Partial Class ControlA2
Inherits System.Web.UI.UserControl
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
PlaceHolder1.Controls.Clear()
Dim toAdd As Control = LoadControl("ControlX.ascx")
PlaceHolder1.Controls.Add(toAdd)
End Sub
End Class
'Here is ControlA2 designer
I am Control A
Add Control X
asp:Button ID="Button1" runat="server" Text="Add Control X"
asp:PlaceHolder ID="PlaceHolder1" runat="server"
/asp:PlaceHolder
'Here is ControlB.ascx
Partial Class ControlA2
Inherits System.Web.UI.UserControl
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
PlaceHolder1.Controls.Clear()
Dim toAdd As Control = LoadControl("ControlZ.ascx")
PlaceHolder1.Controls.Add(toAdd)
End Sub
End Class
'Here is ControlB designer
I am Control B
Add Control Z
asp:Button ID="Button1" runat="server" Text="Add Control Z"
asp:PlaceHolder ID="PlaceHolder1" runat="server" /asp:PlaceHolder
'Here is ControlX.designer
asp:Label ID="Label1" runat="server" Text="Label">I AM CONTROL X /asp:Label
'Here is ControlZ designer
asp:Label ID="Label1" runat="server" Text="Label">I AM CONTROL Z /asp:Label
I've created a project based on your code and I've managed to recreate the issue.
When I initially run it and click on the Add control A button the Main control will load Control A and note this in the viewstate. Control A's button to add Control X will now appear with an id of Main1_ctl00_Button1. When clicking on this button Main's page load will add Control A back to it's placeholder and Control A's button click event will fire. If you now click Main's Control A button again the problem arises. Main's page load method will look at the Viewstate and add control A to the placeholder. Then Main's button click event will then fire clearing the placeholder and re-adding control A. When the form is displayed Control A's button to add Control X will now have an id of Main1_ctl01_Button1 as it was the second control to be generated in the code behind. Now when you click on the button to add control x Main's page load will add Control A again but as it's id will be Main1_ctl00_Button1 and the click event came from a button with an id of Main1_ctl01_Button1 the event will not fire.
To fix this you will have to avoid the duplication of control creation the second time around. You could do this by checking the requests form collection during the page load to see which button was pressed although this is not a very elegant solution. You will need to ensure that the buttons on the Main control have a unique text value for this to work.
Hopefully someone else may be able to come up with a more elegant solution:
Dim mainButtonClick = False
For index As Integer = 0 To Request.Form.Count
If Request.Form(index) = "Button A" Or Request.Form(index) = "Button B" Then
mainButtonClick = True
End If
Next
If Not IsPostBack And Not mainButtonClick And ViewState("name") <> String.Empty Then
AddControl(ViewState("name").ToString())
End If
Please excuse any errors in this code as I am not a VB.NET programmer.

Resources