User control not updating


S

sqlboy2000

Hello all,
I have something very simple going on here and I'm scratching my head
as to what the problem is. There are 4 items in my project, 2 webforms,
a user control, and a module:

WebForm1.aspx
ChangeValue.aspx
WebUserControl1.ascx
Module1.vb

Here's the flow:
WebForm1 is the start page and has a placeholder that gets populated
with WebUserControl1. Module1.vb has a public variable called strTest.
The page load of WebForm1 set this string to "Some Value". (Provided
it's not a postback)
On WebUserControl1, there is a textbox and a label. The page load of
the usercontrol sets the values of both the textbox and the label to
the value of strTest. (So it gets set to "Some Value" on the first
load. There is a plain old html button on WebUserControl1 that executes
some client script to open a popup window. The popup window opens
ChangeValue.aspx.
ChangeValue.aspx has some code in the page load that changes the value
of strTest from "Some Value" to "New Value". It also has a button that
executes some client script to refresh the parent window and close the
popup.
So the value of both the textbox and the label in the usercontrol
should now read "New Value". However, ONLY the label is getting
updated. This is utterly confusing, my page is definitely getting
refreshed or the label would still say "Some Value" instead of "New
Value". The code for each of the 4 items follows, I can't figure this
one out for the life of me. Any help would be appreciated.

Here's Module1:

Module Module1

Public strTest As String

End Module


Here's WebForm1.aspx (HTML):

<body>
<form id="Form1" method="post" runat="server">
<asp:placeHolder id="PlaceHolder1" runat="server"></asp:placeHolder>
</form>
</body>


Here's WebForm1.aspx (Code Behind):

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
strTest = "Some Value"
End If



Dim ctrTextBox As WebUserControl1


PlaceHolder1.Controls.Clear()
ctrTextBox = LoadControl("WebUserControl1.ascx")
ctrTextBox.ID = "WebUC1"
PlaceHolder1.Controls.Add(ctrTextBox)
End Sub


Here's WebUserControl1.ascx (HTML):

<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<br>
<asp:Label id="Label1" runat="server">Label</asp:Label><br>
<INPUT type="button" value="Open Popup"
onclick="window.open('ChangeValue.aspx')">

Here's WebUserControl1.ascx (VB):

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

TextBox1.Text = strTest
Label1.Text = strTest

End Sub

Here's ChangeValue.aspx (HTML):

<body>
<form id="Form1" method="post" runat="server">
<INPUT type="button" value="Change variable and reload parent"
onclick = "reloadAndClose()">
</form>
</body>

Here's ChangeValue.aspx (VB):


<HEAD>

<script>
function reloadAndClose() {
window.opener.document.Form1.submit();

window.close();

}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT type="button" value="Change variable and reload parent"
onclick = "reloadAndClose()">
</form>
</body>
 
Ad

Advertisements

G

Guest

Sorry, here you go:

ChangeValue.aspx (VB)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
strTest = "New Value"
End Sub

ChangeValue.aspx (HTML)

<HTML>
<HEAD>

<script>
function reloadAndClose() {
window.opener.document.Form1.submit();

window.close();

}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT type="button" value="Change variable and reload parent" onclick =
"reloadAndClose()">
</form>
</body>
</HTML>
 
G

Guest

Yeah I noticed the same thing, if it's all one page it works fine, it only
doesn't work on the user control. But I'm stuck with the user controls in
this case, and it's MS recommended to use them so I want to be a good citizen.
Thanks for your help.
 
G

Guest

not 100% sure I followed BUT...
you say you are calling the parent page to refresh... is this being
recognized in the code-behind as NOT a PostBack(), since its really not, and
the value is being reset?
 
G

Guest

Thank you. At least I'm not going crazy. Maybe.

Curt_C said:
I was able to recreate... Looking into it now.
The variable is indeed set to the right value, it's just something with the
rendering of the TextBox that's the issue.
 
Ad

Advertisements

G

Guest

That's why I included the code, it's a very small project.

The popup is refreshing the parent. It's working perfectly for the label,
but the textbox is not updating. The core question being, why is the label
being updated but not the textbox? The code is identical:

TextBox1.Text = strTest
Label1.Text = strTest

Jeff
 
Ad

Advertisements

G

Guest

I was able to come up with a workaround, if I put the code in the prerender
event of textbox instead of the page load event, the textbox get's refreshed
with the correct value. Seems like a hokey solution, any input here MS?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top