DropDownList1.SelectedIndexChanged not working - asp.net

Protected Sub DropDownList1_SelectedIndexChanged(
ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Context.Response.Write("selectedindexchanged")
End Sub
Why is this not working?

Have you put Autopostback = true for the dropdown list

Related

Asp.net Vb.net , access control concurrency

Hello guys I am trying to make restriction on my WebApp that runs on VB.net with framework Asp.net. In another words, how can I Control the permitted number of sessions.
The WebApp works perfectly and now I want to add "How many users can access the WebApp" if Number of users "Sessions" exceeded the new coming users will be redirected to a site.
I have been working on this for few weeks... tried Cookies and Seasons and neither is working
Scenario: Maximum users can access the WebApp is 1
when I launch the second Browser and start new session the UserNumber will be incremented by 1 hence will be redirected to "ServerBusy" page...
However, If the second Browser opened new tab and accessed the WebApp that will bypass the Condition at Session_Start and will access the WebApp .
Thank you.
here is the Code
Imports System.Web
Public Class Global_asax
Inherits System.Web.HttpApplication
Public Shared maxUsersAllowance As Integer = 1 'Total number of users can enter the server
Public Shared UserNumber As Integer = 0 ' the current number of users
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
UserNumber = UserNumber + 1
Dim myCookie As New HttpCookie("UserNumber")
Dim myCookie2 As New HttpCookie("Access")
myCookie.Value = UserNumber
myCookie2.Value = True
Response.Cookies.Add(myCookie)
Response.Cookies.Add(myCookie2)
If (Request.Cookies("UserNumber") IsNot Nothing) Then
If (Request.Cookies("UserNumber").Value > 1) Then
If (Request.Cookies("Access").Value) Then
Response.Redirect("~/ServerBusy.aspx")
End If
End If
End If
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_Init(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_Dispose(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_Unload(ByVal sender As Object, ByVal e As EventArgs)
End Sub
End Class
After Reading Article https://stackoverflow.com/a/6218525/1260204 and Updating the code, the Issue still exist which is that the User Can get into the WebApp if he open new Tab on the browser and connected
Imports System.Web
Public Class Global_asax
Inherits System.Web.HttpApplication
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Application("ActiveSessions") = 0
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Try
Application.Lock()
Dim activeSessions As Integer = CInt(Application("ActiveSessions")) + 1
Dim allowedSessions As Integer = 1
' retrieve the threshold here instead
Application("ActiveSessions") = activeSessions
If activeSessions > allowedSessions Then
System.Web.HttpContext.Current.Response.Redirect("~/ServerBusy.aspx", False)
End If
Finally
Application.UnLock()
End Try
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim LiveSessionsCount As Integer = CInt(Application("LiveSessionsCount"))
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Application.Lock()
Application("ActiveSessions") = CInt(Application("ActiveSessions")) - 1
Application.UnLock()
End Sub
End Class
Update, I have solved the Issue with the Tabs. by adding
Session.Abandon()
In my redirected page. However that is half solution as far as i can get to... the other half is , if the user closes his browser by the X , I do need to wait 20 minutes until the session ends ... is there a away to terminate the session once the user exit/kill the page?

asp.net (with vb.net) control array at run time giving error : Object reference not set to an instance of an object

asp.net (with vb.net) control array at run time giving error :
Object reference not set to an instance of an object.
I am getting this error.
My Code is :
Partial Class _Default
Inherits System.Web.UI.Page
Dim chk(10) As CheckBox
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Else
MsgBox("loading")
chk(0) = New CheckBox
With chk(0)
.ID = "chk(0)"
.Text = .ID
End With
Me.form1.Controls.Add(chk(0))
End If
TextBox1.Text = chk(0).Text
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If chk(0).Checked = True Then
MsgBox("Yes")
Else
MsgBox("No")
End If
Response.Redirect("Page1.aspx")
End Sub
End Class
Use this instead:
Dim chk As CheckBox
chk = New CheckBox
Solved !
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Else
MsgBox("loading")
chk(0) = New CheckBox
With chk(0)
.ID = "chk(0)"
.Text = .ID
End With
Me.form1.Controls.Add(chk(0))
End If
TextBox1.Text = chk(0).Text
End Sub

why is recaptcha.IsValid always returns True

why is recaptcha.IsValid always returns True?
Protected Sub CreateUserWizard1_CreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
Dim Captcha As RecaptchaControl = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("recaptcha1"), RecaptchaControl)
If Not Captcha.IsValid Then
e.Cancel = True
End If
End Sub
call Captcha.Validate() before Captcha.IsValid
Protected Sub CreateUserWizard1_CreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
Dim Captcha As RecaptchaControl = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("recaptcha1"), RecaptchaControl)
Captcha.Validate()
If Not Captcha.IsValid Then
e.Cancel = True
End If
End Sub

What's wrong with this VB.net syntax to pass query string?

this code will not pass the query string to default3.aspx on Image Button ..
I think there is some error in my syntax, please help me to sort out the error.. in code below :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ImageButton1.Attributes.Add("onClick", "window.showModalDialog('Default3.aspx?id='" + Label4.Text + ",'','dialogHeight: 400px; dialogWidth: 370px;');return false;")
End Sub
modify code as below
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ImageButton1.Attributes.Add("onClick", "window.showModalDialog('Default3.aspx?id=" + Label4.Text + "','','dialogHeight: 400px; dialogWidth: 370px;');return false;");
End Sub
Hope this will help you...

Refreshing DropdownList data, after a new item has been selected

I have two dropdownlist, one is State and one is City. When a State is selected, the City dropdownlist becomes populated. At that point you can select a city, however if you select a city and go back and select a different state, the city dropdownlist is populated by the cities for both states. How do I get it clear the cities for the first state?
Here is the code behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Public Sub ddlState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
SqlDataSource2.SelectParameters.Clear()
SqlDataSource2.SelectParameters.Add(New Parameter("#State", DbType.String, ddlState.SelectedValue))
ddlCity.DataBind()
'SqlDataSource2.SelectParameters.Clear()
'Dim State As String = ddlState.SelectedItem.Text
End Sub
Protected Sub ddlCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlCity.SelectedIndexChanged
'Dim City As String = ddlCity.SelectedItem.Text
End Sub
Public Sub ddlState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
SqlDataSource2.SelectParameters.Clear()
SqlDataSource2.SelectParameters.Add(New Parameter("#State", DbType.String, ddlState.SelectedValue))
ddlCity.Items.Clear();
ddlCity.Items.Add(new ListItem("SELECT ONE", "")) ' If you want it '
ddlCity.DataBind()
End Sub
You could also set AppendDataboundItems = 'false' in the control.

Resources