Problems with reading Data from a Usercontrol












0















I have the following Problem, i created a C# User Control with a couple of Input fields.



I implemented 2 Main functions ( Set_Data and Read_Data).
Set Data Reads some Data from a Class and Displays it at the User_Control.



Read_Data: Reads the Input value and stores it inside the same Class.



These functions are tested and work properly.



But if i try to use the same User Control to store the Data into another Instance of the same class the Information in the first Class stores the values of the second one too.
Maybe im just doing something wrong.



private Data_Class DataClass1 = new Data_Class();
private Data_Class DataClass2 = new Data_Class();

private void btn_page1_Click(object sender, EventArgs e)
{
page = "page1";
UserControl1.set_Data(DataClass1);
UserControl1.BringToFront();
}

private void btn_page2_Click(object sender, EventArgs e)
{
page = "page2";
UserControl1.set_Data(DataClass2);
UserControl1.BringToFront();
}

private void check_pagechange_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (page != last_page)
{
if (last_page == "page1")
{
DataClass1 = UserControl1.read_Data();
}
if (last_page == "page2")
{
DataClass2 = UserControl1.read_Data();
}
last_page = page;
}
}


As it can be seen i use a Backgroundworker which reads the Data from the Usercontrol when there is a Pagechange.










share|improve this question

























  • Shouldn't that be if (page == "page1") and if (page == "page2") instead of last_page ?

    – AsheraH
    Nov 21 '18 at 10:18











  • I want to read the data whe i leave this page. Therefore whenever a pagechange occurs it should execute the Read_data function and store it into the respective class.

    – Urek
    Nov 21 '18 at 10:22













  • When exactly is "check_pagechange_RunWorkerCompleted" executed? The name of the method makes me assume it is executed some while after "btn_pageX_Click()"? Maybe the issue is there a race condition? From your code I cannot see anything wrong.

    – gofal3
    Nov 21 '18 at 10:34











  • I just tried it without using the Background worker. I Hardcoded the pagechange for a Quick try and the same Problem appears again.

    – Urek
    Nov 21 '18 at 10:49











  • bool variable=false; if (page != last_page) { if (last_page == "page1"&& variable==false) { DataClass1 = UserControl1.read_Data(); variable=true; } Even after this change it still has this behaviour.

    – Urek
    Nov 21 '18 at 11:07


















0















I have the following Problem, i created a C# User Control with a couple of Input fields.



I implemented 2 Main functions ( Set_Data and Read_Data).
Set Data Reads some Data from a Class and Displays it at the User_Control.



Read_Data: Reads the Input value and stores it inside the same Class.



These functions are tested and work properly.



But if i try to use the same User Control to store the Data into another Instance of the same class the Information in the first Class stores the values of the second one too.
Maybe im just doing something wrong.



private Data_Class DataClass1 = new Data_Class();
private Data_Class DataClass2 = new Data_Class();

private void btn_page1_Click(object sender, EventArgs e)
{
page = "page1";
UserControl1.set_Data(DataClass1);
UserControl1.BringToFront();
}

private void btn_page2_Click(object sender, EventArgs e)
{
page = "page2";
UserControl1.set_Data(DataClass2);
UserControl1.BringToFront();
}

private void check_pagechange_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (page != last_page)
{
if (last_page == "page1")
{
DataClass1 = UserControl1.read_Data();
}
if (last_page == "page2")
{
DataClass2 = UserControl1.read_Data();
}
last_page = page;
}
}


As it can be seen i use a Backgroundworker which reads the Data from the Usercontrol when there is a Pagechange.










share|improve this question

























  • Shouldn't that be if (page == "page1") and if (page == "page2") instead of last_page ?

    – AsheraH
    Nov 21 '18 at 10:18











  • I want to read the data whe i leave this page. Therefore whenever a pagechange occurs it should execute the Read_data function and store it into the respective class.

    – Urek
    Nov 21 '18 at 10:22













  • When exactly is "check_pagechange_RunWorkerCompleted" executed? The name of the method makes me assume it is executed some while after "btn_pageX_Click()"? Maybe the issue is there a race condition? From your code I cannot see anything wrong.

    – gofal3
    Nov 21 '18 at 10:34











  • I just tried it without using the Background worker. I Hardcoded the pagechange for a Quick try and the same Problem appears again.

    – Urek
    Nov 21 '18 at 10:49











  • bool variable=false; if (page != last_page) { if (last_page == "page1"&& variable==false) { DataClass1 = UserControl1.read_Data(); variable=true; } Even after this change it still has this behaviour.

    – Urek
    Nov 21 '18 at 11:07
















0












0








0








I have the following Problem, i created a C# User Control with a couple of Input fields.



I implemented 2 Main functions ( Set_Data and Read_Data).
Set Data Reads some Data from a Class and Displays it at the User_Control.



Read_Data: Reads the Input value and stores it inside the same Class.



These functions are tested and work properly.



But if i try to use the same User Control to store the Data into another Instance of the same class the Information in the first Class stores the values of the second one too.
Maybe im just doing something wrong.



private Data_Class DataClass1 = new Data_Class();
private Data_Class DataClass2 = new Data_Class();

private void btn_page1_Click(object sender, EventArgs e)
{
page = "page1";
UserControl1.set_Data(DataClass1);
UserControl1.BringToFront();
}

private void btn_page2_Click(object sender, EventArgs e)
{
page = "page2";
UserControl1.set_Data(DataClass2);
UserControl1.BringToFront();
}

private void check_pagechange_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (page != last_page)
{
if (last_page == "page1")
{
DataClass1 = UserControl1.read_Data();
}
if (last_page == "page2")
{
DataClass2 = UserControl1.read_Data();
}
last_page = page;
}
}


As it can be seen i use a Backgroundworker which reads the Data from the Usercontrol when there is a Pagechange.










share|improve this question
















I have the following Problem, i created a C# User Control with a couple of Input fields.



I implemented 2 Main functions ( Set_Data and Read_Data).
Set Data Reads some Data from a Class and Displays it at the User_Control.



Read_Data: Reads the Input value and stores it inside the same Class.



These functions are tested and work properly.



But if i try to use the same User Control to store the Data into another Instance of the same class the Information in the first Class stores the values of the second one too.
Maybe im just doing something wrong.



private Data_Class DataClass1 = new Data_Class();
private Data_Class DataClass2 = new Data_Class();

private void btn_page1_Click(object sender, EventArgs e)
{
page = "page1";
UserControl1.set_Data(DataClass1);
UserControl1.BringToFront();
}

private void btn_page2_Click(object sender, EventArgs e)
{
page = "page2";
UserControl1.set_Data(DataClass2);
UserControl1.BringToFront();
}

private void check_pagechange_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (page != last_page)
{
if (last_page == "page1")
{
DataClass1 = UserControl1.read_Data();
}
if (last_page == "page2")
{
DataClass2 = UserControl1.read_Data();
}
last_page = page;
}
}


As it can be seen i use a Backgroundworker which reads the Data from the Usercontrol when there is a Pagechange.







c# asp.net user-controls






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 13:02









Mohan Rajput

271312




271312










asked Nov 21 '18 at 10:13









UrekUrek

11




11













  • Shouldn't that be if (page == "page1") and if (page == "page2") instead of last_page ?

    – AsheraH
    Nov 21 '18 at 10:18











  • I want to read the data whe i leave this page. Therefore whenever a pagechange occurs it should execute the Read_data function and store it into the respective class.

    – Urek
    Nov 21 '18 at 10:22













  • When exactly is "check_pagechange_RunWorkerCompleted" executed? The name of the method makes me assume it is executed some while after "btn_pageX_Click()"? Maybe the issue is there a race condition? From your code I cannot see anything wrong.

    – gofal3
    Nov 21 '18 at 10:34











  • I just tried it without using the Background worker. I Hardcoded the pagechange for a Quick try and the same Problem appears again.

    – Urek
    Nov 21 '18 at 10:49











  • bool variable=false; if (page != last_page) { if (last_page == "page1"&& variable==false) { DataClass1 = UserControl1.read_Data(); variable=true; } Even after this change it still has this behaviour.

    – Urek
    Nov 21 '18 at 11:07





















  • Shouldn't that be if (page == "page1") and if (page == "page2") instead of last_page ?

    – AsheraH
    Nov 21 '18 at 10:18











  • I want to read the data whe i leave this page. Therefore whenever a pagechange occurs it should execute the Read_data function and store it into the respective class.

    – Urek
    Nov 21 '18 at 10:22













  • When exactly is "check_pagechange_RunWorkerCompleted" executed? The name of the method makes me assume it is executed some while after "btn_pageX_Click()"? Maybe the issue is there a race condition? From your code I cannot see anything wrong.

    – gofal3
    Nov 21 '18 at 10:34











  • I just tried it without using the Background worker. I Hardcoded the pagechange for a Quick try and the same Problem appears again.

    – Urek
    Nov 21 '18 at 10:49











  • bool variable=false; if (page != last_page) { if (last_page == "page1"&& variable==false) { DataClass1 = UserControl1.read_Data(); variable=true; } Even after this change it still has this behaviour.

    – Urek
    Nov 21 '18 at 11:07



















Shouldn't that be if (page == "page1") and if (page == "page2") instead of last_page ?

– AsheraH
Nov 21 '18 at 10:18





Shouldn't that be if (page == "page1") and if (page == "page2") instead of last_page ?

– AsheraH
Nov 21 '18 at 10:18













I want to read the data whe i leave this page. Therefore whenever a pagechange occurs it should execute the Read_data function and store it into the respective class.

– Urek
Nov 21 '18 at 10:22







I want to read the data whe i leave this page. Therefore whenever a pagechange occurs it should execute the Read_data function and store it into the respective class.

– Urek
Nov 21 '18 at 10:22















When exactly is "check_pagechange_RunWorkerCompleted" executed? The name of the method makes me assume it is executed some while after "btn_pageX_Click()"? Maybe the issue is there a race condition? From your code I cannot see anything wrong.

– gofal3
Nov 21 '18 at 10:34





When exactly is "check_pagechange_RunWorkerCompleted" executed? The name of the method makes me assume it is executed some while after "btn_pageX_Click()"? Maybe the issue is there a race condition? From your code I cannot see anything wrong.

– gofal3
Nov 21 '18 at 10:34













I just tried it without using the Background worker. I Hardcoded the pagechange for a Quick try and the same Problem appears again.

– Urek
Nov 21 '18 at 10:49





I just tried it without using the Background worker. I Hardcoded the pagechange for a Quick try and the same Problem appears again.

– Urek
Nov 21 '18 at 10:49













bool variable=false; if (page != last_page) { if (last_page == "page1"&& variable==false) { DataClass1 = UserControl1.read_Data(); variable=true; } Even after this change it still has this behaviour.

– Urek
Nov 21 '18 at 11:07







bool variable=false; if (page != last_page) { if (last_page == "page1"&& variable==false) { DataClass1 = UserControl1.read_Data(); variable=true; } Even after this change it still has this behaviour.

– Urek
Nov 21 '18 at 11:07














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409745%2fproblems-with-reading-data-from-a-usercontrol%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409745%2fproblems-with-reading-data-from-a-usercontrol%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

WPF add header to Image with URL pettitions [duplicate]