ラベル dear の投稿を表示しています。 すべての投稿を表示
ラベル dear の投稿を表示しています。 すべての投稿を表示

2012年3月26日月曜日

retaining class state.

dear All

I have a checkbox, a dropdownlistbox and a label in 3 separate update panels.

I have autopostback=true for both checkbox and dropdownlist box and write to the label text in their eventhandlers. The checkbox event when fired writes as expected but not the dropdownlistbox.

I have a class called myclass with a string property called "abrev". I want to remember the complete myclass between postbacks. I think there is something called session to do it...but can someone help me on how to do it in the below code?

aspx.cs code.

public partialclass _Default : System.Web.UI.Page { myclass[] pessi =new myclass[10];protected void Page_Load(object sender, EventArgs e) { ScriptManager1.RegisterAsyncPostBackControl(CheckBox1); ScriptManager1.RegisterAsyncPostBackControl(DropDownList1);for (int i = 0; i < 10; i++) { pessi[i] =new myclass(); } }protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { DropDownList1.Items.Clear(); DropDownList1.Items.Add("something"); DropDownList1.Items.Add("something1"); pessi[0].Abrev ="I am in checkbox"; Label2.Text = pessi[0].Abrev; UpdatePanel2.Update(); UpdatePanel3.Update(); }protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Label2.Text = pessi[0].Abrev; UpdatePanel3.Update(); }}
 
aspx code 
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <br /> <br /> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:CheckBox ID="CheckBox1" runat="server" autopostback="true" OnCheckedChanged="CheckBox1_CheckedChanged" /> </ContentTemplate> </asp:UpdatePanel> <br /> <br /> <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" autopostback="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> <br /> <br /> <asp:UpdatePanel ID="UpdatePanel3" UpdateMode="Conditional" runat="server"> <ContentTemplate> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </form>
  
Thank you all in advance,
prasad.. 

Session Variables are what you want. They are are read/write like any other variable, except they persist in memory on the server for the duration of the visitors session. They are also simple to use:

Session["myvar"] = "var";
Response.Write["myvar"]; //will outputvar



hi

Thank you for your reply.

I am a little new to the world of programming and computers as such (not a SW professional). Can you please tell me how to store a complete class?

will this work for my above example?

Session["myname"] = "myclass";

Secondly, where should this session be defined= in pageload? and also when there is a postback?

lastly, I want to be able to change any property of myclass in the code behind when events happen...do these changes automatically take place in the session..

for example...if I change myclass.Abrev (in my example) for a button click event for example then are the session variables updated automatically?

Thank you in advancem

prasad..

2012年3月24日土曜日

RightClick Menu

Dear Team

I am using ASP.NET2.0, C#, JavaScript, AJAX

I want to make a right click menu working on GridView, with some items inside the meun, and when I press on it I can handle it from Javascript or from server side and I can fill this menu from Server side if it is possible.

So how can I do that?

Thank you.

dear Team
i did use the control found in this site:http://msdn.microsoft.com/msdnmag/issues/05/02/CuttingEdge/

i am working with ASP.NET2.0, C#, AJAX, JAVASCRIPT.

if you please i want to know the following:
1 - why dose the context menu postback, i mean if i want only to use it in the client side, is there a way for it.
2 - i am using the context menu with a gridview so i want to know the current row index, from javascript and if possible from C# too.
3 - i want to know what i clicked on the menu from Javascript.

please advise me what to do.
i am stuck in this problem for 1 week now and i didnt find any solution.
i want you to know that i download the control and i use it sand it is working for me but i want to know these point that will solve my whole problem.

thank you so much in advance.
this is my Email:
zonzone@.hotmail.com