Hi Everybody

I am using ASP.NET 2.0
In my application, i want to use session concept
I have a user control, in which i have to set the default values for some controls to be session variables.
eg: for a dropdown list i am using -1 as the defualt value
here i want to set a session variable as
session("var1") = -1

Now when my page loads, in the page load, user control will display the dropdwonlist with -1 values

Now the user changes the value in dropdownlist to 2

How can i update the session("var1") to the newly selected value from the user control?

I also want to mention that i have a button in the user control which i am planning to do the refresh after changing any value in the user control

so in the button click, how can i reset the session varible values?
Initially where do i have to set the session("var1") = -1 in usercontrol--- in page init or in page load

Hope I am not confusing you all

Hope someone will help me to figure it out

thanks

The session variable can be set practically anywhere. I'd set it in the page.load section.

To update the variable when the selected dropdownlist value is changed you have to do a postback.

Just put an onSelectedIndexChanged event on the dropdownbox in which you set the session variable to the selected value.

Protected Sub dropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dropDownList.SelectedIndexChanged
     Session("var1") = sender.SelectedValue
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.