Rank: Member Groups: Member
Joined: 3/8/2011 Posts: 19
|
Hi I have a asp.net control with a multiline textbox and a 2 linkbutton. 1st Linkbutton opens a dialog(opens with showbutton property) which shows a list where items are selected and then a OK button is clicked and selected items must be dispalyed in the textbox This event creates the entire page postback. I wanted to do this with the call back So I placed the callback control and moved the textbox in to it. now the trigger if i put OK button it gives some error. May be it does not recognize the button of dialog Let me know what to do following is the code
Code: HTML/ASPX
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ADPeoplePicker.ascx.vb" Inherits="NMDC_EDMS.ADPeoplePicker" %>
<%@ Register TagPrefix="eo" NameSpace="EO.Web" Assembly="EO.Web" %>
<link rel="Stylesheet" type="text/css" href="/MasterStyle.css" id="style" runat="server" visible="false" />
<script type="text/javascript" language="javascript">
function ClearValues(a, b) {
if (a != null)
a.value = "";
if (b != null)
b.value = "";
}
function btnOk_Click(id, name, cmb) {
if (cmb != null) {
var listLength = cmb.options.length;
for (var i = 0; i < listLength; i++) {
if (cmb.options[i].selected) {
//lst2.options.add(sel.options[i].text);
//lst2.options[list2length] = new Option(sel.options[i].text);
//list2length++;
//alert(cmb.options[i].value);
//alert(cmb.options[i].text);
if (id.value == "") {
id.value = cmb.options[i].value;
name.value = cmb.options[i].text;
}
else {
id.value = id.value + ", " + cmb.options[i].value;
name.value = name.value + ", " + cmb.options[i].text;
}
}
}
}
}
</script>
<div class="entry">
<eo:CallbackPanel id="CallbackPanel1121" runat="server" Triggers="{ControlID:btnOk;Parameter:ok},{ControlID:btnSelect;Parameter:select},{ControlID:btnClear;Parameter:clear}"
LoadingHTML="Loading..." OnExecute="btnSearch_Click">
<asp:TextBox ID="txtBoxSelectedPersonName" runat="server" ReadOnly="True" CssClass="post"
TextMode="MultiLine" Width="300px"></asp:TextBox>
<asp:TextBox ID="txtBoxSelectedADLoginId" runat="server" ReadOnly="true" Width="0px" Height="0px" ></asp:TextBox>
</eo:CallbackPanel>
<asp:LinkButton ID="btnSelect" Text="Select" runat="server"></asp:LinkButton>
<asp:LinkButton ID="btnClear" Text="Clear" runat="server"></asp:LinkButton>
<eo:Dialog runat="server" id="Dialog1" ControlSkinID="None" Width="412px" HeaderHtml='"padding-top:5px">Select Person(s)</div>'
Height="312px" BackColor="#ECE9D8" CloseButtonUrl="00020440" AcceptButton="btnOk" AcceptButtonPostBack="true" ClientSideOnAccept="changeDialogOpenValue"
HeaderImageUrl="00020441" HeaderImageHeight="27" AllowResize="True" MinHeight="100" MinWidth="150" IsModal="true" >
<FooterStyleActive CssText="padding-right: 4px; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; padding-top: 4px; font-family: tahoma"></FooterStyleActive>
<HeaderStyleActive CssText="background-image:url(00020442);color:#444444;font-family:'trebuchet ms';font-size:10pt;font-weight:bold;padding-a:0px;padding-b:0px;padding-bottom:7px;padding-c:0px;padding-d:0px;padding-left:8px;padding-right:0px;padding-top:0px;"></HeaderStyleActive>
<ContentStyleActive CssText="background-color:#f0f0f0;font-family:tahoma;font-size:8pt;padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;"></ContentStyleActive>
<BorderImages BottomBorder="00020409,00020429" RightBorder="00020407,00020427" TopRightCornerBottom="00020405,00020425"
TopRightCorner="00020403,00020423" LeftBorder="00020406,00020426" TopLeftCorner="00020401,00020421"
BottomRightCorner="00020410,00020430" TopLeftCornerBottom="00020404,00020424" BottomLeftCorner="00020408,00020428"
TopBorder="00020402,00020422"></BorderImages>
<ContentTemplate>
<asp:ListBox SelectionMode="Multiple" Height="270px" Width="400px" ID="lstADUsers" runat="server" ></asp:ListBox>
<br />
<p style="color:Black">Press Ctrl Key to select multiple people</p>
<center>
<asp:Button ID="btnOk" text="Ok" runat="server" CausesValidation="false" />
</center>
</ContentTemplate>
</eo:Dialog>
</div>
Code: Visual Basic.NET
Imports System.DirectoryServices
Imports System.Data
Imports NMDC_EDMS.clsMyADClass
Public Class ADPeoplePicker
Inherits System.Web.UI.UserControl
Public Property MultiSelect As Boolean
Set(ByVal value As Boolean)
If value = True Then
lstADUsers.SelectionMode = ListSelectionMode.Multiple
lstADUsers.ToolTip = "Press Ctrl Key for multi selection"
Else
lstADUsers.SelectionMode = ListSelectionMode.Single
End If
End Set
Get
If lstADUsers.SelectionMode = ListSelectionMode.Multiple Then
Return True
Else
Return False
End If
End Get
End Property
Public Property Value As String
Set(ByVal value As String)
txtBoxSelectedADLoginId.Text = value
Dim adArray As String() = txtBoxSelectedADLoginId.Text.Split(",")
Dim i As Integer
For i = 0 To adArray.Length - 1
If txtBoxSelectedPersonName.Text = "" Then
txtBoxSelectedPersonName.Text = GetUserInfo(adArray(i).ToString, "cn")
Else
txtBoxSelectedPersonName.Text += ", " & GetUserInfo(adArray(i).ToString, "cn")
End If
Next
End Set
Get
Return txtBoxSelectedADLoginId.Text
End Get
End Property
Public ReadOnly Property Text As String
Get
Return txtBoxSelectedPersonName.Text
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = True Then
'If IsNothing(ViewState("dsusers")) = False Then
' 'Dim dsusers As DataSet = CType(ViewState("dsusers"), DataSet)
' 'lstADUsers.DataSource = dsusers
' 'lstADUsers.DataMember = "dtusers"
' 'lstADUsers.DataTextField = "FullName"
' 'lstADUsers.DataValueField = "LoginName"
' 'lstADUsers.DataBind()
'End If
'If DialogOpen.Value.ToString = "1" Then
' Dialog1.Show()
'End If
End If
If IsPostBack = False Then
Dialog1.ShowButton = btnSelect.ClientID
btnOk.Attributes.Add("OnClientClick", "btnOk_Click(" & txtBoxSelectedADLoginId.ClientID & "," & txtBoxSelectedPersonName.ClientID & "," & lstADUsers.ClientID & ")")
btnSearch_Click(Nothing, Nothing)
End If
End Sub
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EO.Web.CallbackEventArgs)
Dim action As String = "select"
If IsNothing(e) = False Then
action = e.Parameter
End If
If action = "select" Then
Dim dsusers As DataSet = New DataSet
lstADUsers.ClearSelection()
FillDataset(dsusers)
lstADUsers.DataSource = dsusers
lstADUsers.DataMember = "dtusers"
lstADUsers.DataTextField = "FullName"
lstADUsers.DataValueField = "LoginName"
lstADUsers.DataBind()
ViewState("dsusers") = dsusers
ElseIf action = "clear" Then
txtBoxSelectedADLoginId.Text = Nothing
txtBoxSelectedPersonName.Text = Nothing
ElseIf action = "ok" Then
btnOk_Click(Nothing, Nothing)
End If
End Sub
Private Sub FillDataset(ByVal dsusers As DataSet)
Dim i As Integer = 0
Try
Dim sPath As String = ConfigurationManager.ConnectionStrings("ADConnectionString").ConnectionString
Dim entry As New DirectoryServices.DirectoryEntry(sPath)
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult
Dim resultCol As System.DirectoryServices.SearchResultCollection
Dim so As New System.DirectoryServices.SortOption
so.Direction = SortDirection.Ascending
so.PropertyName = "DisplayName"
mySearcher.Sort = so
mySearcher.PropertiesToLoad.Add("samaccountname")
mySearcher.PropertiesToLoad.Add("DisplayName")
mySearcher.PropertiesToLoad.Add("title")
'
dsusers.Tables.Clear()
dsusers.Tables.Add("dtUsers")
dsusers.Tables(0).Columns.Add(New DataColumn("LoginName"))
dsusers.Tables(0).Columns.Add(New DataColumn("FullName"))
dsusers.Tables(0).Columns.Add(New DataColumn("title"))
dsusers.Tables(0).Columns.Add(New DataColumn("DropDownTextCol"))
Dim pk(0) As System.Data.DataColumn
pk(0) = dsusers.Tables(0).Columns("LoginName")
dsusers.Tables(0).PrimaryKey = pk
'
mySearcher.Filter = ("(&(objectClass=user)(objectCategory=person))")
mySearcher.PageSize = 1000
resultCol = mySearcher.FindAll()
If Not (resultCol Is DBNull.Value) Then
Dim row As DataRow
While i < resultCol.Count
result = resultCol(i)
row = dsusers.Tables(0).NewRow
'If (result.Properties.Contains("samaccountname")) And (result.Properties.Contains("DisplayName")) And _
' (result.Properties.Contains("title")) And (result.Properties.Contains("mail")) And _
'(result.Properties.Contains("description")) Then
If Not result.Properties("samaccountname").Count = 0 Then
row("LoginName") = result.Properties("samaccountname").Item(0).ToString()
End If
If Not result.Properties("DisplayName").Count = 0 Then
row("FullName") = result.Properties("DisplayName").Item(0).ToString()
End If
If Not result.Properties("title").Count = 0 Then
row("title") = result.Properties("title").Item(0).ToString()
End If
'If Not IsNothing(result.Properties("description").Item(0)) Then
row("DropDownTextCol") = row("FullName").ToString & " - " & row("title").ToString
dsusers.Tables(0).Rows.Add(row)
'End If
i += 1
End While
End If
Catch ex As Exception
' Response.Write(ex.Message)
End Try
End Sub
Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOk.Click
For Each lstItem As ListItem In lstADUsers.Items
If lstItem.Selected = True Then
If txtBoxSelectedADLoginId.Text = "" Then
txtBoxSelectedADLoginId.Text = lstItem.Value
txtBoxSelectedPersonName.Text = lstItem.Text
Else
txtBoxSelectedADLoginId.Text += "," & lstItem.Value
txtBoxSelectedPersonName.Text += "," & lstItem.Text
End If
End If
Next
ViewState("dsusers") = Nothing
End Sub
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClear.Click
txtBoxSelectedADLoginId.Text = Nothing
txtBoxSelectedPersonName.Text = Nothing
End Sub
End Class
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
The trigger button of a CallbackPanel and the CallbackPanel itself must be inside the same naming container. Because the dialog is a naming container, you will not be able to use a Button inside the dialog as a trigger to a CallbackPanel outside of the dialog.
To work around this problem, you can add a second CallbackPanel (say CallbackPanel B) inside your dialog and set the OK button as B's trigger. You would then set your original CallbackPanel (say CallbackPanel A)'s GroupName and B's GroupName to the same value. This way when you click the button, B is triggered (because B's trigger is set to the button), but A is also triggered (because A and B are in the same "group").
Hope this helps.
Thanks!
|
Rank: Member Groups: Member
Joined: 3/8/2011 Posts: 19
|
I did what you advised me. But if the dialog autopostbackonaccept=true only then it executes the ok button code, but it will refresh the whole page.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
That's normal. When you set AcceptButton, the dialog, not the button will be triggering the post back. I don't see any reason why you want to use accept button when you are alreadying using CallbackPanel.
Thanks
|