SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using three webparts. Webpart A creates a value when the user clicks on the button in Webpart A. WebPart B uses this value to create a list with items the user can select. WebPart C uses both values to create a string for testing purposes.

WebPart B uses this list to fill a dropdownbox. Whenever the selectedvalue is changed it should update WebPart C. This is the declaration of the control.

_documentTypeList = new DropDownList();
_documentTypeList.AutoPostBack = true;

The problem here is that using

_documentTypeList.AutoPostBack = true;

reloads the complete page and resets the value in WebPart A to null. How do i send WebPart B's new value to WebPart C without losing the value of WebPart A? This all happens on 1 page.

share|improve this question
up vote 9 down vote accepted

saving session state varibles can be done using:

    public string Name
            return Page.Session["SaveName"] as string;
            Page.Session["SaveName"] = value;

this is a getter/setter to save/get from session state

to use this do the following:

this gets the value from session state (needs to be in onPreRender event to see session state varibles)

txtName.Text = Name;

this sets into session state (can be anywhere you want to save to session state)

Name = txtName.Text;

for int valuse:

cahnge public string Name to public int Name and same goes for anything else like bool values ect.

so it would look like this for int:

    public int Name
            return Page.Session["SaveName"] as int;
            Page.Session["SaveName"] = value;

As others have noted for data to be passed between webpart you should be using the iInterface method:

provide (webpart sending data) consumer (webpart using that data) and interface that is the connection between the webparts:

the above will 100% work and save your values on postback :)

just incase you need this ;) iv posted some links on connections below.

Connectable WebPart Problems......................?


Connection between 2 web parts

hope it helps :)

share|improve this answer
I managed to fix it on a different way but this is still a great solution to my problem. Thank You! – user1746525 Dec 19 '12 at 13:13
Why are you enabling the viewstate if you are talking about sessionstate before? – Norbert Dec 19 '12 at 13:28
yup your right I dont know why iv added that in, well spotted :P – ali Sharepoint Dec 19 '12 at 14:09

Have you tried if (!Page.IsPostBack) { your code here } ?

share|improve this answer

Have you tried creating custom web part connection for your purpose? Going through your requirement may be that's the most appropriate option

share|improve this answer
All three webparts are currently using custom Web Part Connections. They are connected as follows. A -> B, A -> C, B -> C. Changing the value in WebPart A doesn't have any consequences for B and C. But changing the Value of WebPart B and using the _documentTypeList.AutoPostBack = true; it refreshes the page recreating all webparts (thus removing WebPart A's Value). – user1746525 Dec 19 '12 at 10:56
do you really need the auto postback? i can not realize your exact scenario, if you see that it's absolutely necessary then you may want to save the required value in viewstate – Diptarag Dec 19 '12 at 11:00
I don't need the auto postback. I'd be happy to use any other way to get it to work. I can expand on the scenario if that makes it any easier. – user1746525 Dec 19 '12 at 11:04
if you can post your details scenario, that would be helpful – Diptarag Dec 19 '12 at 11:10
I am creating one webpart which login on a webservice (WebPart A) the value is a unique ticket. The Second webpart creates a dropdownlist with every Document Type available (WebPart B) the document types are returned by a second webservice. The second webservice requires the unique ticket. The third webpart currently only shows both values but will later be expanded to show all docmetadata from the selected Document Type. The docmetadata also gets returned from the second webservice and requires both the unique ticket and a document type. – user1746525 Dec 19 '12 at 11:19

Previously the web parts where connected with in the following order.

WebPart A => WebPart B
WebPart B => WebPart C
WebPart A => WebPart C

this created an error if i wanted to call both values in WebPart C when i changed the value in WebPart B. Whenever WebPart B's value was changed it was required to reload the page and therfore reloading WebPart A. Because WebPart A had a value which is created on user interaction and not on page load the value was lost. WebPart B and WebPart C seized to function without the value of WebPart A. If you wish to keep the WebPart Connection as described above please check almostSharePointMaster's answer.

Because in my case WebPart A creates a unique login token i'd rather not save it to the page. I'd prefer keeping it withing the WebParts. To do so i changed the connection between them. Instead above connection i used the following connection.

WebPart A => WebPart B => WebPart C

Webpart B saves the value of WebPart A and provides it together with his own value to WebPart C. This is how WebParts B Interface currently looks like.

public interface IWebPartB
    string webPartAValue { get; }
    string webPartBValue { get; }
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.