用户控件未更新 [英] User control not updating

查看:74
本文介绍了用户控件未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在这里有一些非常简单的事情,我在摸不着头脑。

问题是什么。我的项目中有4个项目,2个webforms,

a用户控件和一个模块:


WebForm1.aspx

ChangeValue .aspx

WebUserControl1.ascx

Module1.vb


这里是流程:

WebForm1是起始页面,有一个占位符,使用WebUserControl1填充

。 Module1.vb有一个名为strTest的公共变量。

WebForm1的页面加载将此字符串设置为Some Value。 (提供

它不是回发)

在WebUserControl1上,有一个文本框和一个标签。页面加载

usercontrol将文本框和标签的值设置为

strTest的值。 (因此它在第一个

加载时被设置为Some Value。在WebUserControl1上有一个普通的旧html按钮执行

一些客户端脚本来打开一个弹出窗口窗口。弹出窗口打开

ChangeValue.aspx。

ChangeValue.aspx在页面加载中有一些代码改变了strTest的价值

从Some Value到New Value。它还有一个按钮,

执行一些客户端脚本来刷新父窗口并关闭

弹出窗口。

因此,usercontrol

中的文本框和标签的值现在应该是新值。但是,只有标签才能获得

更新。这完全令人困惑,我的页面肯定会刷新,或者标签仍然会说Some Value而不是New

Value。这4个项目中的每个项目的代码如下,我不能认为这是我的生活中的一个问题。任何帮助我很感激。


这里是模块1:


模块模块1


公共测试作为字符串


结束模块

这里是'WebForm1.aspx(HTML):


< body> ;

< form id =" Form1"方法= QUOT;交" runat =" server">

< asp:PlaceHolder id =" PlaceHolder1" runat =" server">< / asp:PlaceHolder>

< / form>

< / body>

这里's WebForm1.aspx(代码背后):


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)Handles MyBase.Load

''用户代码初始化页面

如果不是Page.IsPostBack则

strTest =" Some Value"

结束如果


Dim ctrTextBox As WebUserControl1

PlaceHolder1.Controls.Clear()

ctrTextBox = LoadControl(" WebUserControl1.ascx")

ctrTextBox.ID =" WebUC1"

PlaceHolder1.Controls.Add(ctrTextBox)

End Sub

这里是'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'')">


这里'' s WebUserControl1.ascx(VB):


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

''用户代码初始化页面


TextBox1.Text = strTest

Label1.Text = strTest


结束子


这里是ChangeValue.aspx(HTML):


< body> ;

< form id =" Form1"方法= QUOT;交" runat =" server">

< INPUT type =" button" value ="更改变量并重新加载父级"

onclick =" reloadAndClose()">

< / form>

< / body>


这里是'ChangeValue.aspx(VB):

< HEAD>


< script>

函数reloadAndClose(){

window.opener.document.Form1.submit();


window.close();


}

< / script>

< / HEAD>

< body>

< form id =" Form1"方法= QUOT;交" runat =" server">

< INPUT type =" button" value ="更改变量并重新加载父级"

onclick =" reloadAndClose()">

< / form>

< / body>

解决方案

我能够重新创建...现在调查。

变量确实设置为正确的值,它只是文本框的

渲染的问题。


-

Curt Christianson

网站: http: //www.darkfalz.com

博客: http:/ /blog.darkfalz.com


" sqlboy2000"写道:

这就是为什么我包含了代码,这是一个非常小的项目。

弹出窗口让父母更新。它完全适用于标签,
但文本框没有更新。核心问题是,为什么标签更新而不是文本框?代码完全相同:

TextBox1.Text = strTest
Label1.Text = strTest

杰夫

" Curt_C [MVP] "写道:

不是100%肯定我跟着但是......
你说你正在呼叫父页面刷新......这是否被认可了代码隐藏不是PostBack(),因为它真的没有,而且值正在被重置?

-
Curt Christianson
网站:< a rel =nofollowhref =http://www.darkfalz.comtarget =_ blank> http://www.darkfalz.com
博客: http://blog.darkfalz.com

" sqlboy2000"写道:

大家好,
我在这里有一些非常简单的事情,我正在摸索着问题是什么。我的项目有4个项目,2个webforms,
用户控件和模块:

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

这里是流程:
WebForm1是起始页面,有一个占位符,用WebUserControl1填充
。 Module1.vb有一个名为strTest的公共变量。
WebForm1的页面加载将此字符串设置为Some Value。 (提供
它不是回发)
在WebUserControl1上,有一个文本框和一个标签。用户控件的页面加载将文本框和标签的值设置为strTest的值。 (因此它在第一个
加载时设置为Some Value。在WebUserControl1上有一个普通的旧html按钮,它执行一些客户端脚本以打开一个弹出窗口。弹出窗口打开
ChangeValue.aspx。
ChangeValue.aspx在页面加载中有一些代码,它们将strTest的值从Some Value更改为New Value。它还有一个按钮
执行一些客户端脚本来刷新父窗口并关闭弹出窗口。
因此,用户控件中文本框和标签的值现在应该是新值。但是,只有标签才会更新。这完全令人困惑,我的页面肯定会刷新,或者标签仍然会说Some Value而不是New
Value对于这4个项目中的每个项目的代码如下,我不能认为这对我来说是一个生命。任何帮助都会受到赞赏。

这里是模块1 :
模块模块1

Public StrTest As String

结束模块

这里是'WebForm1.aspx(HTML):

< body>
< form id =" Form1"方法= QUOT;交" runat =" server">
< asp:PlaceHolder id =" PlaceHolder1" runat =" server">< / asp:PlaceHolder>
< / form>
< / body>

这里是'WebForm1.aspx(代码后面):私有Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load
''用户代码初始化页面这里
如果不是Page.IsPostBack那么
strTest =" Some Value"
结束如果

Dim ctrTextBox As WebUserControl1

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

这里是'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'')">

这里是WebUserControl1.ascx(VB):

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load
''用户代码初始化页面

TextBox1.Text = strTest
Label1.Text = strTest

End Sub

这里是ChangeValue.aspx(HTML):

< body>
< form id =" Form1"方法= QUOT;交" runat =" server">
< INPUT type =" button" value ="更改变量并重新加载父级
onclick =" reloadAndClose()">
< / form>
< / body>
这里是ChangeValue.aspx(VB):

< HEAD>

< script>
函数reloadAndClose(){
窗口.opener.document.Form1.submit();

window.close();

}
< / script>
< / HEAD>
< body>
< form id =" Form1"方法= QUOT;交" runat =" server">
< INPUT type =" button" value ="更改变量并重新加载父级
onclick =" reloadAndClose()">
< / form>
< / body>



对不起,你走了:


ChangeValue.aspx(VB)


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

''将用户代码置于此处初始化页面

strTest ="新值

结束子


ChangeValue.aspx(HTML )


< HTML>

< HEAD>


< script>

函数reloadAndClose(){

window.opener.document.Form1.submit();


window.close();


}

< / script>

< / HEAD>

< body>

< form id =" Form1"方法= QUOT;交" runat =" server">

< INPUT type =" button" value ="更改变量并重新加载父级 onclick =

" reloadAndClose()">

< / form>

< / body>

< / HTML>


" Curt_C [MVP]"写道:

ChangeValue.aspx的.vb在哪里?还是没有它? (你发布了两次HTML)

-
Curt Christianson
网站: http://www.darkfalz.com
博客: http://blog.darkfalz.com

" sqlboy2000"写道:

这就是为什么我包含了代码,这是一个非常小的项目。

弹出窗口让父母更新。它完全适用于标签,
但文本框没有更新。核心问题是,为什么标签更新而不是文本框?代码完全相同:

TextBox1.Text = strTest
Label1.Text = strTest

杰夫

" Curt_C [MVP] "写道:

不是100%肯定我跟着但是......
你说你正在呼叫父页面刷新......这是否被认可了代码隐藏不是PostBack(),因为它真的没有,而且值正在被重置?

-
Curt Christianson
网站:< a rel =nofollowhref =http://www.darkfalz.comtarget =_ blank> http://www.darkfalz.com
博客: http://blog.darkfalz.com

" sqlboy2000"写道:

>大家好,
>我有一些非常简单的事情在这里,我正在挠挠脑袋
>至于问题是什么。我的项目中有4个项目,2个webforms,
>用户控件和模块:
>
> WebForm1.aspx
> ChangeValue.aspx
> WebUserControl1.ascx
> Module1.vb
>
>这是流程:
> WebForm1是起始页面,并且有一个占位符,可以填充
>使用WebUserControl1。 Module1.vb有一个名为strTest的公共变量。
> WebForm1的页面加载将此字符串设置为Some Value。 (提供
>这不是回发)
>在WebUserControl1上,有一个文本框和一个标签。页面加载
> usercontrol将文本框和标签的值设置为
> strTest的值。 (因此它在第一个
>加载时设置为Some Value。在WebUserControl1上有一个普通的旧html按钮,用于执行
>某些客户端脚本以打开弹出窗口。弹出窗口窗口打开
> ChangeValue.aspx。
> ChangeValue.aspx在页面加载中有一些代码,它将strTest的值从Some Value更改为New值。它还有一个按钮,
>执行一些客户端脚本来刷新父窗口并关闭
>弹出窗口。
>所以文本框和文本框的值都是用户控件中的标签
>现在应该读取新值。但是,只有标签才会更新。这非常令人困惑,我的页面肯定会得到
>刷新或标签仍然会说Some Value而不是New
> Value。以下4项中的每一项的代码如下,我无法想象这个
>一为了我的生命。任何帮助将不胜感激。
>
>这是模块1:
>
>模块模块1
>
>公共strTest As String
>
>结束模块
>
>
>这里是WebForm1.aspx(HTML):
>
> < body>
> < form id =" Form1"方法= QUOT;交" runat =" server">
> < asp:PlaceHolder id =" PlaceHolder1" runat =" server">< / asp:PlaceHolder>
> < / form>
> < / body>
>
>
>这里是WebForm1.aspx(代码背后):
>
> Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
> System.EventArgs)处理MyBase.Load
> ''将用户代码置于此处初始化页面
>如果不是Page.IsPostBack那么
> strTest =" Some Value"
>结束如果
>
>
>
> Dim ctrTextBox As WebUserControl1
>
>
> PlaceHolder1.Controls.Clear()
> ctrTextBox = LoadControl(" WebUserControl1.ascx")
> ctrTextBox.ID =" WebUC1"
> PlaceHolder1.Controls.Add(ctrTextBox)
>结束子
>
>
>这里是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'')">
>
>这里是WebUserControl1.ascx(VB):
>
> Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
> System.EventArgs)处理MyBase.Load
> ''用户代码在此处初始化页面
>
> TextBox1.Text = strTest
> Label1.Text = strTest
>
>结束子
>
>这里是ChangeValue.aspx(HTML):
>
> < body>
> < form id =" Form1"方法= QUOT;交" runat =" server">
> < INPUT type =" button" value ="更改变量并重新加载父级
> onclick =" reloadAndClose()">
> < / form>
> < / body>
>
>这里是ChangeValue.aspx(VB):
>
>
> < HEAD>
>
> < script>
> function reloadAndClose(){
> window.opener.document.Form1.submit();
>
> window.close();
>
> }
> < / script>
> < / HEAD>
> < body>
> < form id =" Form1"方法= QUOT;交" runat =" server">
> < INPUT type =" button" value ="更改变量并重新加载父级
> onclick =" reloadAndClose()">
> < / form>
> < / body>
>
>



是的,我注意到同样的事情,如果它只是一个页面它工作正常,它只有

不能用于用户控件。但是我坚持使用

这个案例中的用户控件,而且MS建议使用它们,所以我想成为一个好公民。

谢谢为了你的帮助。


" Curt_C [MVP]"写道:

如果你把控件放在页面上它工作正常...

很奇怪...我今晚会更多地研究它没有人找到解决方案,但是我在文本框上假设它与渲染事件有一些对比。

-
Curt Christianson
网站: http://www.darkfalz.com
博客: http://blog.darkfalz.com

" sqlboy2000"写道:

对不起,在这里你去:

ChangeValue.aspx(VB)

私有子Page_Load(ByVal发送者作为系统.Object,ByVal e As
System.EventArgs)处理MyBase.Load
''设置用户代码来初始化页面
strTest =" New Value"
End Sub

ChangeValue.aspx(HTML)
< HTML>
< HEAD>

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

window.close();

}
< /脚本>
< / HEAD>
< body>
< form id =" Form1"方法= QUOT;交" runat =" server">
< INPUT type =" button" value ="更改变量并重新加载父级 onclick =
" reloadAndClose()">
< / form>
< / body>
< / HTML>


Curt_C [MVP]"写道:

ChangeValue.aspx的.vb在哪里?还是没有它? (你发布了两次HTML)

-
Curt Christianson
网站: http://www.darkfalz.com
博客: http://blog.darkfalz.com

" sqlboy2000"写道:

>这就是我加入代码的原因,这是一个非常小的项目。
>
>弹出窗口正在刷新父级。这对标签非常有效,
>但文本框没有更新。核心问题是,为什么标签是
>正在更新但不是文本框?代码完全相同:
>
> TextBox1.Text = strTest
> Label1.Text = strTest
>
>杰夫
>
> Curt_C [MVP]写道:
>
> >不是100%肯定我跟着但是...
> >你说你正在呼叫父页面刷新......这是
> >在代码隐藏中被识别为不是PostBack(),因为它真的不是,并且
> >价值正在重置?
> >
> > -
> > Curt Christianson
> > site: http://www.darkfalz.com
> >博客: http://blog.darkfalz.com
> >
> >
> >
> > " sqlboy2000"写道:
> >
> > >大家好,
> > >我有一些非常简单的事情在这里,我正在挠挠脑袋
> > >至于问题是什么。我的项目中有4个项目,2个webforms,
> > >用户控件和模块:
> > >
> > > WebForm1.aspx
> > > ChangeValue.aspx
> > > WebUserControl1.ascx
> > > Module1.vb
> > >
> > >这是流程:
> > > WebForm1是起始页面,并且有一个占位符,可以填充
> > >使用WebUserControl1。 Module1.vb有一个名为strTest的公共变量。
> > > WebForm1的页面加载将此字符串设置为Some Value。 (提供
>>>这不是回发)
> > >在WebUserControl1上,有一个文本框和一个标签。页面加载
> > > usercontrol将文本框和标签的值设置为
> > > strTest的值。 (因此它在第一个
>>>加载时设置为Some Value。在WebUserControl1上有一个普通的旧html按钮,用于执行
>>>某些客户端脚本打开一个弹出窗口。弹出窗口打开
>>> ChangeValue.aspx。
>>> ChangeValue.aspx在页面加载中有一些代码更改值
>>> of strTest从Some Value到New Value。它还有一个按钮,
>>>执行一些客户端脚本来刷新父窗口并关闭
>>>弹出窗口。
>>>因此,用户控件
>>>中的文本框和标签的值现在应该是 ;新值。但是,只有标签才会更新
>>>。这完全令人困惑,我的页面肯定会刷新
>>>刷新或标签仍然说Some Value而不是New
>>> Value&qu OT ;.以下4个项目的代码如下,我无法想象这个
> > >一个为了我的生命。任何帮助将不胜感激。
> > >
> > >这是模块1:
> > >
> > >模块模块1
> > >
> > >公共strTest As String
> > >
> > >结束模块
> > >
> > >
> > >这里是WebForm1.aspx(HTML):
> > >
> > > < body>
> > > < form id =" Form1"方法= QUOT;交" runat =" server">
> > > < asp:PlaceHolder id =" PlaceHolder1" runat =" server">< / asp:PlaceHolder>
> > > < / form>
> > > < / body>
> > >
> > >
> > >这里是WebForm1.aspx(代码背后):
> > >
> > > Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
>>>> System.EventArgs)处理MyBase.Load
> > > ''将用户代码置于此处初始化页面
> > >如果不是Page.IsPostBack那么
> > > strTest =" Some Value"
> > >结束如果
> > >
> > >
> > >
> > > Dim ctrTextBox As WebUserControl1
> > >
> > >
> > > PlaceHolder1.Controls.Clear()
> > > ctrTextBox = LoadControl(" WebUserControl1.ascx")
> > > ctrTextBox.ID =" WebUC1"
> > > PlaceHolder1.Controls.Add(ctrTextBox)
> > >结束子
> > >
> > >
> > >这里是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'')">
> > >
> > >这里是WebUserControl1.ascx(VB):
> > >
> > > Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
>>>> System.EventArgs)处理MyBase.Load
> > > ''将用户代码置于此处初始化页面
> > >
> > > TextBox1.Text = strTest
> > > Label1.Text = strTest
> > >
> > >结束子
> > >
> > >这里是ChangeValue.aspx(HTML):
> > >
> > > < body>
> > > < form id =" Form1"方法= QUOT;交" runat =" server">
> > > < INPUT type =" button" value ="更改变量并重新加载父级
> > > onclick =" reloadAndClose()">
> > > < / form>
> > > < / body>
> > >
> > >这里是ChangeValue.aspx(VB):
> > >
> > >
> > > < HEAD>
> > >
> > > < script>
> > > function reloadAndClose(){
> > > window.opener.document.Form1.submit();
> > >
> > > window.close();
> > >
> > > }
> > > < / script>
> > > < / HEAD>
> > > < body>
> > > < form id =" Form1"方法= QUOT;交" runat =" server">
> > > < INPUT type =" button" value ="更改变量并重新加载父级
> > > onclick =" reloadAndClose()">
> > > < / form>
> > > < / body>
> > >
> > >



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>

解决方案

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.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"sqlboy2000" wrote:

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

"Curt_C [MVP]" wrote:

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?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"sqlboy2000" wrote:

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>



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>


"Curt_C [MVP]" wrote:

where is the .vb for ChangeValue.aspx? or is there nothign in it? (you posted
the html twice)

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"sqlboy2000" wrote:

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

"Curt_C [MVP]" wrote:

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?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"sqlboy2000" wrote:

> 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>
>
>



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.

"Curt_C [MVP]" wrote:

if you put the control on the page it works fine...

Weird... I''ll look into it more tonight if no one finds a solution, but I''m
assuming its somethign with the Render event on the textbox.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"sqlboy2000" wrote:

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>


"Curt_C [MVP]" wrote:

where is the .vb for ChangeValue.aspx? or is there nothign in it? (you posted
the html twice)

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"sqlboy2000" wrote:

> 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
>
> "Curt_C [MVP]" wrote:
>
> > 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?
> >
> > --
> > Curt Christianson
> > site: http://www.darkfalz.com
> > blog: http://blog.darkfalz.com
> >
> >
> >
> > "sqlboy2000" wrote:
> >
> > > 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>
> > >
> > >



这篇关于用户控件未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆