When I make use of the Timer event tick to trigger an animated update panel refresh I get the following error:
TypeError: sender._activeElement is undefined
Sys.Extended.UI.Animation.UpdatePanelAnimationBehavior.prototype._partialUpdateBeginRequest()
ScriptResource.axd:75
Function$createDelegate/<()
ScriptResource.axd:47
Sys$EventHandlerList$getHandler/<()
ScriptResource.axd:3484
Sys$WebForms$PageRequestManager$_onFormSubmit()
ScriptResource.axd:1284
Sys$WebForms$PageRequestManager$_doPostBack()
ScriptResource.axd:824
Function$createDelegate/<()
ScriptResource.axd:47
Sys$UI$_Timer$_doPostback()
ScriptResource.axd:60
Sys$UI$_Timer$_raiseTick()
ScriptResource.axd:91
Function$createDelegate/<()
If I use a button click event it works fine animations and all, but I need it timed. If I remove the UpdatePanelAnimationExtender the timer refresh works fine but I don't get the animations.
I am using Ajax Control Toolkit 16.
<%# Page Language="VB" AutoEventWireup="True" CodeFile="Test2.aspx.vb" Inherits="_Default" Debug="True" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="ds2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
<div><div style="float:right; color:gray;"><asp:Label Visible="true" ID="Label1" runat="server" Text="1"></asp:Label></div>
<ajaxToolkit:UpdatePanelAnimationExtender ID="UpdatePanelAnimationExtender1" runat="server" TargetControlID="logoUpdatePanel">
<Animations><OnUpdating><Sequence>
<EnableAction AnimationTarget="effect_color" Enabled="true" />
<EnableAction AnimationTarget="effect_collapse" Enabled="true" />
<EnableAction AnimationTarget="effect_fade" Enabled="true" />
<Parallel Duration="1" Fps="20">
<FadeOut AnimationTarget="PanelInfo" minimumOpacity=".2" />
<color AnimationTarget="PanelInfo" StartValue="#FFEF3F" EndValue="#FFFFFF" Property="style" PropertyKey="backgroundColor" />
</Parallel></Sequence></OnUpdating>
<OnUpdated>
<Sequence>
<EnableAction AnimationTarget="effect_collapse" Enabled="true" />
<EnableAction AnimationTarget="effect_fade" Enabled="true" />
<Parallel Duration="1" Fps="20">
<FadeIn AnimationTarget="logoUpdatePanel" />
<Resize Height="0" />
</Parallel>
</Sequence>
</OnUpdated></Animations>
</ajaxToolkit:UpdatePanelAnimationExtender>
<asp:UpdatePanel ID="logoUpdatePanel" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Image ID="Logo1" runat="server" ImageUrl="~/Images/RBCCCW_1080p_Horizontal.jpg" ImageAlign="Middle" />
<asp:Label Visible="false" runat="server" ID="TableCount" Text="tablecount"></asp:Label>
<asp:Label visible="false" runat="server" ID="rowcount" Text="rowcount"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" updatemode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="bindlist"></asp:Timer>
<asp:DataList ID="RoomEventsList" runat="server" Width="1080px" CellPadding="10" CellSpacing="5" HeaderStyle-BackColor="#0060AA" AlternatingItemStyle-BackColor="#a8cde2" Font-Size="24pt">
<HeaderTemplate>
<div class="colhead1">Start</div><div class="colhead2">Events</div>
</HeaderTemplate>
<ItemTemplate>
<div class="col1"><%#Eval("fstf").ToString.ToLower()%></div><div class="col2"><span style="font-weight:bold"><%#Eval("EV700_ALT_FUNC_DESC")%></span> <br /><span style="float:right;font-size:22pt"> <%#Eval("EV800_SPACE_DESC")%> | <%#Eval("EV812_HIER_LVL2_DESC")%> | <%#Eval("EV811_HIER_LVL1_DESC")%> </span></div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
<table width="100%"><tr><td></td><td align="right">
<asp:Label Visible="false" runat="server" ID="pagenumber" Text="start"></asp:Label><asp:Label Visible="false" ID="lblTotalPages" runat="server" Text="1"></asp:Label></td></tr></table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
and the code behind:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Collections.Generic
Imports System.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Dim pagedDSr As New PagedDataSource()
Dim totalPages As Integer
Dim totalImages As Integer
Public Property CurrentPage() As Integer
Get
Return IIf(ViewState("CurrentPage") Is Nothing, 0, CInt(ViewState("CurrentPage")))
End Get
Set(value As Integer)
ViewState("CurrentPage") = value
End Set
End Property
Public Property imagecount() As Integer
Get
Return IIf(ViewState("imagecount") Is Nothing, 0, CInt(ViewState("imagecount")))
End Get
Set(value As Integer)
ViewState("imagecount") = value
End Set
End Property
Public Property imageSize() As String
Get
Return IIf(ViewState("imageSize") Is Nothing, "", CStr(ViewState("imageSize")))
End Get
Set(value As String)
ViewState("imageSize") = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack() Then
CurrentPage = 0
imagecount = 1
TableCount.Text = "0"
bindlist()
End If
End Sub
Sub changelogo()
Logo1.ImageUrl = "~/Images/" & imagesize & "/" & imagecount & ".jpg"
If imagecount = IO.Directory.GetFiles("C:\inetpub\digsignall\Images\" & imageSize & "\", "*.jpg").Length Then
imagecount = 1
TableCount.Text = imagecount.ToString
Else
imagecount = imagecount + 1
TableCount.Text = imagecount.ToString
End If
End Sub
Sub bindlist()
Dim strConnString As String = ConfigurationManager.ConnectionStrings("ebmsprodCS").ConnectionString
Dim con As New SqlConnection(strConnString)
Using conn As New SqlConnection(strConnString)
Dim varname1 As New System.Text.StringBuilder
varname1.Append("SELECT statement removed for space")
Dim cmd As New SqlCommand(varname1.ToString, conn)
cmd.CommandType = CommandType.Text
conn.Open()
'Dim drEvents As SqlDataReader = cmd.ExecuteReader()
Dim eventsda = New SqlDataAdapter(cmd)
Dim ds = New DataSet
eventsda.Fill(ds, "events")
If ds.Tables(0).Rows.Count <= 0 Then
RoomEventsList.Visible = False
imagesize = "fullscreen"
rowcount.Text = IO.Directory.GetFiles("C:\inetpub\digsignall\Images\" & imageSize & "\", "*.jpg").Length
changelogo()
Else
RoomEventsList.Visible = True
imageSize = "top"
changelogo()
End If
pagedDSr.DataSource = ds.Tables(0).DefaultView
pagedDSr.AllowPaging = True
pagedDSr.PageSize = 10
pagedDSr.CurrentPageIndex = CurrentPage
totalPages = pagedDSr.PageCount
RoomEventsList.DataSource = pagedDSr
RoomEventsList.DataBind()
conn.Close()
Label1.Text = Request.QueryString("room")
End Using
If pagedDSr.IsLastPage Then
CurrentPage = 0
Else
CurrentPage = CurrentPage + 1
End If
pagenumber.Text = CurrentPage.ToString
End Sub
Protected Sub bindlist_tick()
pagedDSr.CurrentPageIndex = CurrentPage
RoomEventsList.DataSource = pagedDSr
RoomEventsList.DataBind()
If pagedDSr.IsLastPage Then
CurrentPage = 0
Else
CurrentPage = CurrentPage + 1
End If
pagenumber.Text = CurrentPage.ToString
End Sub
End Class
Related
I want to display list of clinics details in listview. From MasterPage Users selects the city & If he goes to clinincs page then list of hospitals display from selected city. Now If I use ViewState in my clinics page then It does not gets clinics data from selected city So what I have done I store City session & on clinics page I have used Session instead of ViewState Which is now working right but my datagaer stopped working. If I have to see another page from datapager then it doesn't switch over. Here is my code
MasterPage
Protected Sub locationSelector_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles locationSelector.TextChanged
Session("masterLocation") = locationSelector.text
Session("Data") = Nothing
End Sub
Clinics Page
Private Sub hospitals_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
Try
If Not Session("Data") Is Nothing Then
hospitals.DataSource = Session("Data")
hospitals.DataBind()
Else
Dim citySelector As Label = Page.Master.FindControl("locationPopupActivator")
query = "select hospitalid, name, address, thumbnail, serviceID, mondayFrom, mondayTo, consultancyFees, city from hospitals Where city Like '" + citySelector.Text + "%' and status = 'active'"
Dim cmd As New MySqlCommand(query, con)
cmd.CommandTimeout = 120
Dim da As New MySqlDataAdapter(cmd)
Dim table As New DataTable
da.Fill(table)
Session("Data") = table
hospitals.DataSource = table
hospitals.DataBind()
End If
'mainCount.Text = table.Rows(0)("countRows").ToString
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
Protected Sub DataPager1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Try
Dim table As DataTable = Session("Data")
hospitals.DataSource = table
hospitals.DataBind()
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
Listview on ASPX
<asp:ListView ID="hospitals" runat="server" DataKeyNames="hospitalID" DataKey="hospitalID">
<ItemTemplate>
My Content
</ItemTemplate>
<EmptyDataTemplate>
<div class="not-found">
<p>
Sorry! Selected Query Not Found</p>
<center>
<img src="images/not-found.jpg" /></center>
</div>
</EmptyDataTemplate>
<LayoutTemplate>
<ul id="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
<div class="datapager" style="padding-bottom: 10px;">
<asp:DataPager ID="DataPager1" runat="server" PageSize="10" PagedControlID="hospitals" ViewStateMode="Enabled">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true" ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
This is working sample of your page:
hospital.master
<%# Master Language="VB" CodeFile="hospital.master.vb" Inherits="hospital_master" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sm" runat="server" />
<div>
<asp:Label ID="lblLockSel" runat="server" AssociatedControlID="locationSelector">Locator Selector</asp:Label>
<asp:UpdatePanel ID="upLocSel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="locationSelector" runat="server" AutoPostBack="true"></asp:TextBox>
<asp:Label ID="locationPopupActivator" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
hospital.master.vb
Partial Class hospital_master
Inherits System.Web.UI.MasterPage
Protected Sub locationSelector_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles locationSelector.TextChanged
Session("masterLocation") = locationSelector.Text
Session("Data") = Nothing
locationPopupActivator.Text = locationSelector.Text
End Sub
End Class
clinics.aspx
<%# Page Title="" Language="VB" MasterPageFile="~/hospital.master" AutoEventWireup="false" CodeFile="clinics.aspx.vb" Inherits="Clinics" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="upHospitals" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:ListView ID="hospitals" runat="server" DataKeyNames="hospitalID" DataKey="hospitalID">
<ItemTemplate>
<%--My Content--%>
<li>
<asp:HyperLink ID="lnkHospital" runat="server" NavigateUrl='<%#Eval("hospitalID", "~/hospital.aspx?id={0}") %>' Text='<%#Eval("Name") %>'></asp:HyperLink>
</li>
</ItemTemplate>
<EmptyDataTemplate>
<div class="not-found">
<p>
Sorry! Selected Query Not Found</p>
<center><%--<center>Is Deprecated Use div with CSS</center>--%>
<img src="images/not-found.jpg" /></center>
</div>
</EmptyDataTemplate>
<LayoutTemplate>
<ul>
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
<%--Inside Update Panel dataPager should be outside paged control--%>
<div class="datapager" style="padding-bottom: 10px;">
<asp:DataPager ID="DataPager1" runat="server" PageSize="10" PagedControlID="hospitals"><%-- ViewStateMode="Enabled"> this is default--%>
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true" ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
clinics.aspx.vb
Partial Class Clinics
Inherits System.Web.UI.Page
Private Sub Clinics_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Session.Remove("Data") 'init
End If
End Sub
Private Sub hospitals_PagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs) Handles hospitals.PagePropertiesChanging
DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
hospitals.DataSource = GetData() 'Session("Data")
hospitals.DataBind()
End Sub
Private Sub hospitals_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
hospitals.DataSource = GetData()
hospitals.DataBind()
End Sub
Private Function GetData() As Data.DataTable
Try
If Session("Data") IsNot Nothing Then
Return Session("Data")
Else
'This is MS SQL server. If you use MySQL then change types accordingly
DataPager1.SetPageProperties(0, DataPager1.PageSize, False) 'reinit
Dim citySelector As Label = Page.Master.FindControl("locationPopupActivator")
Using con As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ClinicsCNN").ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand("select hospitalid, name, address, thumbnail, serviceID, mondayFrom, mondayTo, consultancyFees, city from hospitals Where city Like #city and status = 'active'", con)
cmd.CommandType = Data.CommandType.Text
cmd.Parameters.Add("#city", Data.SqlDbType.VarChar, 50).Value = citySelector.Text & "%" 'same as Session("masterLocation")
Dim table As New Data.DataTable()
Dim da As New Data.SqlClient.SqlDataAdapter(cmd)
da.Fill(table)
da.Dispose()
cmd.Dispose()
Session("Data") = table
Return table
End Using
End If
Catch ex As Exception
Response.Write(ex) 'for debug purpose
Return Nothing
End Try
End Function
End Class
Do you accept this solution?
Ok, after your comments here is my code that works for me:
Private Sub hospitals_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
Try
If Session("Data") Is Nothing Then
Dim citySelector As Label = Page.Master.FindControl("locationPopupActivator")
query = "select hospitalid, name, address, thumbnail, serviceID, mondayFrom, mondayTo, consultancyFees, city from hospitals Where city Like '" + citySelector.Text + "%' and status = 'active'"
Dim cmd As New MySqlCommand(query, con)
cmd.CommandTimeout = 120
Dim da As New MySqlDataAdapter(cmd)
Dim table As New DataTable
da.Fill(table)
Session("Data") = table
hospitals.DataSource = table
hospitals.DataBind()
End If
'mainCount.Text = table.Rows(0)("countRows").ToString
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
protected void hospitals_PagePropertiesChanging(object sender, System.Web.UI.WebControls.PagePropertiesChangingEventArgs e)
{
var datapager = ((DataPager)hospitals.FindControl("DataPager1"));
datapager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
hospitals.DataSource = Session["Data"];
hospitals.DataBind();
datapager.DataBind();
}
I don't think you need DataPager1_PreRender method at all so probably you should remove it all together. You will need to attach new event to your list view: OnPagePropertiesChanging="hospitals_PagePropertiesChanging". Sorry for code in c#, but I don't know VB very well ;)
I am using Visual Studio 2013. I have a ASP.net (vb) Webforms site with asp.net identity. I trying to create a page that manages User role and create roles. I cant find any help online for this when it comes to web forms. This code works for asp.net membership but not for Identity. Here is my code.
Please help Thanks.
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin.Security
Imports Owin
Partial Class AssignRoles
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Roles.AddUserToRole(DropDownList5.SelectedValue, DropDownList6.SelectedValue)
Label1.Text = DropDownList5.SelectedValue + " Was added to the " + DropDownList6.SelectedValue + " Role."
End Sub
Protected Sub btnremoverole_Click(sender As Object, e As EventArgs) Handles btnremoverole.Click
Roles.RemoveUserFromRole(DropDownList3.SelectedValue, DropDownList4.SelectedValue)
Label1.Text = DropDownList3.SelectedValue + " Was removed from the " + DropDownList4.SelectedValue + " Role."
End Sub
Protected Sub CreateRole_Click(sender As Object, e As EventArgs) Handles CreateRole.Click
Dim createRole As String = RoleTextBox.Text
Try
If Roles.RoleExists(createRole) Then
Msg.Text = "Role '" & Server.HtmlEncode(createRole) & "' already exists. Please specify a different role name."
Return
End If
Roles.CreateRole(createRole)
Msg.Text = "Role '" & Server.HtmlEncode(createRole) & "' created."
' Re-bind roles to GridView.
Catch
Msg.Text = "Role '" & Server.HtmlEncode(createRole) & "' <u>not</u> created."
End Try
End Sub
End Class
Here is the Markup code
<%# Page Title="Admin Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true"CodeBehind="AssignRoles.aspx.vb" Inherits="Conflict_Minerals.AssignRoles" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="row">
<div class="col-md-12">
<h2>Admin Panel</h2>
<br />
</div>
<div class="col-md-8">
<asp:Label ID="Label3" runat="server" Text="Add user to role: "></asp:Label>
<asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserName">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="Name">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Add user to role" />
</div>
<div class="col-md-8">
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Remove user from role: "></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserName">
</asp:DropDownList>
 <asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource2" DataTextField="RoleName" DataValueField="RoleName">
</asp:DropDownList>  
<asp:Button ID="btnremoverole" runat="server" Text="Remove user from role" Height="26px" />
<br />
<br />
<div>
<h2>Manage Roles</h2>
</div>
<br />
<asp:TextBox ID="RoleTextBox" runat="server"></asp:TextBox>
<asp:Button ID="CreateRole" runat="server" Text="Create Role" />
<br />
<br />
<asp:Label ID="Msg" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT [Name] FROM [vw_AspNetRoles]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT [UserName] FROM [AspNetUsers]"></asp:SqlDataSource>
<br />
<br />
</div>
</div>
</asp:Content>
I found a solution here is my code
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin.Security
Imports Owin
Partial Class AssignRoles
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim UserManager = New UserManager(Of IdentityUser)(New UserStore(Of IdentityUser)(New IdentityDbContext()))
UserManager.AddToRole(DropDownList5.SelectedValue, DropDownList6.SelectedValue)
Label1.Text = DropDownList5.SelectedItem.Text + " Was added to the " + DropDownList6.SelectedValue + " Role."
End Sub
Protected Sub btnremoverole_Click(sender As Object, e As EventArgs) Handles btnremoverole.Click
Dim UserManager = New UserManager(Of IdentityUser)(New UserStore(Of IdentityUser)(New IdentityDbContext()))
UserManager.RemoveFromRoles(DropDownList3.SelectedValue, DropDownList4.SelectedValue)
Label1.Text = DropDownList3.SelectedItem.Text + " Was removed from the " + DropDownList4.SelectedValue + " Role."
End Sub
Protected Sub CreateRole_Click(sender As Object, e As EventArgs) Handles CreateRole.Click
Dim createRole As String = RoleTextBox.Text
Dim RoleManager = New RoleManager(Of IdentityRole)(New RoleStore(Of IdentityRole)(New ApplicationDbContext()))
Try
If RoleManager.RoleExists(createRole) Then
Msg.Text = "Role '" & Server.HtmlEncode(createRole) & "' already exists. Please specify a different role name."
Return
End If
RoleManager.Create(New IdentityRole(createRole))
Msg.Text = "Role '" & Server.HtmlEncode(createRole) & "' created."
' Re-bind roles to GridView.
Catch
Msg.Text = "Role '" & Server.HtmlEncode(createRole) & "' <u>not</u> created."
End Try
End Sub
End Class
You're going to need to instantiate a RoleManager to work with the roles. From there you can replace your AddRole and RemoveRole code. You will need a UserManager to assign roles to users. Here is a walkthrough for WebForms.http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/membership-and-administration
Here is code:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true"
AsyncPostBackTimeout="1000" ScriptMode="Release"
EnablePartialRendering="true" >
<Services>
<asp:ServiceReference Path ="~/FolderForService/Service.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Path="~/jscript/common.js" />
</Scripts>
</asp:ScriptManager>
<asp:UpdatePanel ID="upFSK" runat ="server" UpdateMode ="Conditional" >
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" >
<asp:TextBox ID="TextBox1" runat="server" Visible="True" Width="128px"></asp:TextBox>
<cc1:AutoCompleteExtender ID="ACE"
runat="server"
ServicePath="~/FolderForService/Service.asmx"
ServiceMethod="WebMethod"
MinimumPrefixLength="4"
CompletionSetCount = "10"
TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>
</Panel>
</ContentTemplate>
</UpdatePanel>
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Linq
Imports System.Web.Caching
Imports System.Data
Imports System.Collections.Generic
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
'Web method which doesn't fire
<WebMethod()> _
Public Shared Function WebMethod(ByVal prefixTekst As String, ByVal count As Integer) As List(Of String)
' Code
End Function
End Class
What I did:
I moved textbox outside Update Panel - 0 points
Changed WebMethod from shared to instance - 0 points
Moved WebService to root - 0 points
Added PostBack=true and Triggers to UpdatePanel with textbox as a trigger - 0 points
Created new WebSite with AutoComplete TextBox and without UpdatePanel - 10 points
What did I miss?
I've only done this in c#, I can give you a c# example if you request it otherwise check out this resource, it should help you get this operational. http://www.aspsnippets.com/Articles/ASP.Net-AJAX-Control-Toolkit-AutoCompleteExtender-without-using-Web-Services.aspx
From the link:
ASP:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods = "true">
</asp:ScriptManager>
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>
VB:
<System.Web.Script.Services.ScriptMethod(), _
System.Web.Services.WebMethod()> _
Public Shared Function SearchCustomers(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
Dim conn As SqlConnection = New SqlConnection
conn.ConnectionString = ConfigurationManager _
.ConnectionStrings("constr").ConnectionString
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "select ContactName from Customers where" & _
" ContactName like #SearchText + '%'"
cmd.Parameters.AddWithValue("#SearchText", prefixText)
cmd.Connection = conn
conn.Open()
Dim customers As List(Of String) = New List(Of String)
Dim sdr As SqlDataReader = cmd.ExecuteReader
While sdr.Read
customers.Add(sdr("ContactName").ToString)
End While
conn.Close()
Return customers
End Function
Set your page property EnableEventValidation="false".It will work.
I'm creating a chat application in asp.net. In this I'm creating tab panels in a tab container dynamically for each user. when you select a new user I'm generating a tab for him with two text boxes and send button to send messages. If he doesn't want to continue his chat I need to remove or delete that tab. Is there any way that i can remove or delete those tabs in asp.net using vb.net?
Here is a complete working sample, it could be broken down into this line(in RemoveTab):
Me.TabContainer1.Tabs.Remove(tab)
But have a look yourself ...
Page-ASPX:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" CombineScripts="true">
</asp:ToolkitScriptManager>
<div>
<asp:UpdatePanel ID="UpdTabContainer" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:TabContainer ID="TabContainer1" runat="server" AutoPostBack="true">
<asp:TabPanel ID="TabUserList" runat="server" HeaderText="UserList">
<ContentTemplate>
<asp:UpdatePanel ID="UpdUserList" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ListBox ID="ListBox1" SelectionMode="Single" AutoPostBack="true" OnSelectedIndexChanged="UserChanged" runat="server">
<asp:ListItem Text="User 1" Value="1"></asp:ListItem>
<asp:ListItem Text="User 2" Value="2"></asp:ListItem>
<asp:ListItem Text="User 3" Value="3"></asp:ListItem>
</asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TabContainer1" EventName="ActiveTabChanged" />
</Triggers>
</asp:UpdatePanel>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Codebehind:
Public Class TabContainerSample
Inherits System.Web.UI.Page
Const idSuffix = "_"c
Property CreatedTabIDs As List(Of String)
Get
If Session("CreatedTabIDs") Is Nothing Then
Session("CreatedTabIDs") = New List(Of String)
End If
Return DirectCast(Session("CreatedTabIDs"), List(Of String))
End Get
Set(value As List(Of String))
Session("CreatedTabIDs") = value
End Set
End Property
Private Sub TabContainerSample_Init(sender As Object, e As System.EventArgs) Handles Me.Init
For Each userID In CreatedTabIDs
AddTab(userID)
Next
End Sub
Private Sub AddTab(tabID As String)
Dim ucChat = DirectCast(Page.LoadControl("ChatControl.ascx"), ChatControl)
ucChat.UserName = tabID
AddHandler ucChat.ChatSubmitted, AddressOf chatSubmitted
AddHandler ucChat.ChatClosed, AddressOf chatClosed
Dim newTabPanel = New AjaxControlToolkit.TabPanel
newTabPanel.ID = String.Format("Tab{0}{1}", idSuffix, tabID)
newTabPanel.HeaderText = String.Format("TabPanel {0}", tabID)
newTabPanel.Controls.Add(ucChat)
TabContainer1.Tabs.Add(newTabPanel)
End Sub
Private Sub RemoveTab(tabID As String)
Dim tab = (From t In Me.TabContainer1.Tabs.Cast(Of AjaxControlToolkit.TabPanel)()
Where t.ID.Contains(idSuffix)
Let id = t.ID.Substring(t.ID.LastIndexOf(idSuffix) + 1)
Where id = tabID
Select t).First
Me.TabContainer1.Tabs.Remove(tab)
Me.CreatedTabIDs.Remove(tabID)
Me.UpdTabContainer.Update()
End Sub
Protected Sub UserChanged(sender As Object, e As EventArgs)
Dim userName = DirectCast(sender, ListBox).SelectedValue
If Not CreatedTabIDs.Contains(userName) Then
AddTab(userName)
CreatedTabIDs.Add(userName)
Me.UpdTabContainer.Update()
End If
End Sub
Private Sub chatSubmitted(chat As ChatControl)
' do something '
End Sub
Private Sub chatClosed(chat As ChatControl)
RemoveTab(chat.UserName)
End Sub
End Class
The Chat-UserControl:
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="ChatControl.ascx.vb" Inherits="WebApplication1.ChatControl" %>
<asp:UpdatePanel ID="UpdChatControl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Username: <asp:Label ID="LblUserName" runat="server" Text="0"></asp:Label>
<br /><asp:TextBox ID="TxtChat" runat="server" TextMode="MultiLine" Rows="4"></asp:TextBox>
<br /><asp:Button ID="BtnSend" runat="server" Text="Send" />
<br /><asp:Button ID="BtnClose" runat="server" Text="Close" />
</ContentTemplate>
</asp:UpdatePanel>
Codebehind:
Public Class ChatControl
Inherits System.Web.UI.UserControl
Public Event ChatSubmitted(sender As ChatControl)
Public Event ChatClosed(sender As ChatControl)
Public Property UserName As String
Get
Return Me.LblUserName.Text
End Get
Set(value As String)
Me.LblUserName.Text = value
End Set
End Property
Public Property ChatText As String
Get
Return Me.TxtChat.Text
End Get
Set(value As String)
Me.TxtChat.Text = value
End Set
End Property
Private Sub BtnSend_Click(sender As Object, e As System.EventArgs) Handles BtnSend.Click
RaiseEvent ChatSubmitted(Me)
Me.UpdChatControl.Update()
End Sub
Private Sub BtnClose_Click(sender As Object, e As System.EventArgs) Handles BtnClose.Click
RaiseEvent ChatClosed(Me)
Me.UpdChatControl.Update()
End Sub
End Class
If you have further question, ask.
I have a pretty simple scenario using manual data operations with rad list view. I insert an item into my collection in the ItemInserting event, the listview shows the new item but the insertitemtemplate is still showing. Is my setup wrong? Do I have to manually hide the thing?
Markup
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Test2.aspx.vb" Inherits="Test2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="rsm"></telerik:RadScriptManager>
<div>
<telerik:RadListView ID="rlv" runat="server" DataKeyNames="UserID" ItemPlaceholderID="itemPlaceholder" Height="400px" AllowPaging="true">
<InsertItemTemplate>
<tr>
<td>
<div style="vertical-align: middle; white-space: nowrap;">
<asp:LinkButton ID="btnInsert2" runat="server" Text="Insert" CommandName='<%# Telerik.Web.UI.RadListView.PerformInsertCommandName %>'></asp:LinkButton>
<asp:LinkButton ID="btnCancel2" runat="server" Text="Cancel" CommandName='<%# Telerik.Web.UI.RadListView.CancelCommandName %>'></asp:LinkButton>
</div>
</td>
<td>
<div style="vertical-align: middle; white-space: nowrap;">
<telerik:RadComboBox id="RadComboBox1" runat="server" autopostback="True" causesvalidation="False" allowcustomtext="True" backcolor="White" emptymessage="Select a Person" enableloadondemand="True" showmoreresultsbox="True" width="150px" dropdownwidth="200px" zindex="9002" enablescreenboundarydetection="False" style="margin-bottom: 0px" datatextfield="UserName" datavaluefield="pkUserID" filter="Contains" onitemsrequested="RCB_ItemsRequested">
<CollapseAnimation Duration="200" Type="OutQuint" />
</telerik:RadComboBox>
</div>
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Literal ID="lName" runat="server" Text='<%# Eval("UserName") %>'></asp:Literal>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<asp:LinkButton ID="btnInsert" runat="server" CausesValidation="False" CommandName='<%# Telerik.Web.UI.RadListView.InitInsertCommandName %>' Text="Add User" />
<table>
<tr>
<td style="border: ridge 1px lightgray">
<strong>Applicable Users</strong>
<table>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</telerik:RadListView>
</div>
</form>
</body>
</html>
Code Behind
Partial Class Test2
Inherits System.Web.UI.Page
Public Property Users As IList(Of UserInfo)
Get
Return If(ViewState("Users"), New List(Of UserInfo))
End Get
Set(ByVal value As IList(Of UserInfo))
ViewState("Users") = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Me.Users = GetInitialUsers()
End If
rlv.DataSource = Users
rlv.DataBind()
Me.ViewState.SetItemDirty("Users", True)
End Sub
Private Function GetInitialUsers() As IList(Of UserInfo)
Dim Users As New List(Of UserInfo)
Users.Add(New UserInfo(1, "1"))
Users.Add(New UserInfo(2, "2"))
Users.Add(New UserInfo(3, "2"))
Users.Add(New UserInfo(4, "4"))
Return Users
End Function
Protected Sub RCB_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
Dim ComboBox As Telerik.Web.UI.RadComboBox = sender
Dim itemOffset As Integer = e.NumberOfItems
Dim NumberOfItems As Integer = 1000000000
Dim Take As Integer = 20
For i As Integer = 0 To Take
ComboBox.Items.Add(New Telerik.Web.UI.RadComboBoxItem(i + itemOffset, (i + itemOffset).ToString))
Next
Dim NumberOfItemsInComboBox As Integer = e.NumberOfItems + ComboBox.Items.Count
If NumberOfItems > 0 Then
e.Message = [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", NumberOfItemsInComboBox, NumberOfItems)
Else
e.Message = "No matches"
End If
e.EndOfItems = (NumberOfItemsInComboBox >= NumberOfItems)
End Sub
Protected Sub rlv_ItemInserting(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewCommandEventArgs) Handles rlv.ItemInserting
Dim ComboBox As Telerik.Web.UI.RadComboBox = e.ListViewItem.FindControl("RadComboBox1")
If Not String.IsNullOrWhiteSpace(ComboBox.SelectedValue) Then
Dim UserID As Integer = ComboBox.SelectedValue
Dim UserName As String = ComboBox.Text
Me.Users.Add(New UserInfo(UserID, UserName))
Else
e.Canceled = True
End If
End Sub
<Serializable()>
Public Class UserInfo
Private _UserID As Integer
Private _UserName As String
Public ReadOnly Property UserID As Integer
Get
Return _UserID
End Get
End Property
Public ReadOnly Property UserName As String
Get
Return _UserName
End Get
End Property
Public Sub New(ByVal UserID As Integer, ByVal UserName As String)
_UserID = UserID
_UserName = UserName
End Sub
End Class
End Class
After you have inserted the new item, set the InsertItemPosition to None:
RadListView1.InsertItemPosition = RadListViewInsertItemPosition.None
radlistview1.IsItemInserted=false;
or set e.canceled=false after save click