点击一个按钮后更新文本框 [英] Update TextBox after a button click
问题描述
我有这样的文本框
:
< ASP:文本框的id =locSelectedCameraGroupName=服务器>< / ASP:文本框>
我有这样的后端code:
保护无效btnCameraGroup_ServerClick(对象发件人,EventArgs的发送)
{
locSelectedCameraGroupName.Text =测试字符串!;
}
这方法点击一个按钮后,名为:
< ASP:LinkButton的ID =btnCameraGroup=服务器的onclick =btnCameraGroup_ServerClick的OnClientClick =ShowCameraGroupPopup()
风格=FONT-SIZE:1.2em;文字修饰:无;光标:指针;背景颜色:灰色;>
!< - TODO:让按钮有圆角CSS ...? - >
< / ASP:LinkButton的>
但是,文本不会更新。这是一个用户的控制。该生产线(根据我的调试器)达到。当我移动行至我的页面加载,它的工作原理。有什么不对,我在做什么?
下面的方法 ShowCameraGroupPopup
只显示/隐藏一些标签,我不认为这有很大的这个问题,但在这里反正是:
函数ShowCameraGroupPopup(){
$('#<%= waitIcon.ClientID%GT;')。节目();
$('#<%= divMainContent.ClientID%GT;')隐藏()。
$(#divCameraGroupPopup)模式(秀)。
返回true;
}
这是点击链接按钮后,流量:
- 的Page_Load命中(被寄回)
- btnCameraGroup_ServerClick按
- 标签名称=第二个选项卡(这是我想要的信息,但由于某种原因,
文字不更新)
解决:我需要一个UpdatePanel(和的ContentTemplate)周围的文本框用触发器(AsyncPostBackTrigger)像这样:
< ASP:的UpdatePanel ID =groupNamePanel=服务器的UpdateMode =条件>
<&触发器GT;
< ASP:AsyncPostBackTrigger控件ID =btnCameraGroup/>
< /触发器>
<&的ContentTemplate GT;
< ASP:文本框的id =locSelectedCameraGroupName=服务器>< / ASP:文本框>
< /&的ContentTemplate GT;
< / ASP:的UpdatePanel>
在codeS如果你的Page_Load()事件,改变的Page_Load()像下面的内容:
块引用>私人无效的Page_Load()
{
如果(!Page.IsPostBack)
{
//复制previous页面加载codeS这里
}
}I have this
TextBox
:<asp:TextBox id="locSelectedCameraGroupName" runat="server" ></asp:TextBox>
I have this back end code:
protected void btnCameraGroup_ServerClick(object sender, EventArgs e) { locSelectedCameraGroupName.Text = "test string!"; }
This method is called after clicking a button:
<asp:linkbutton id="btnCameraGroup" runat="server" onclick="btnCameraGroup_ServerClick" onclientclick="ShowCameraGroupPopup()" style="font-size: 1.2em; text-decoration: none; cursor: pointer; background-color:grey; "> <!-- TODO: Make button have round corners...css? --> </asp:linkbutton>
However, the text does not update. This is a user control. The line is reached (according to my debugger). When I move the line to my page load, it works. Is there something wrong I am doing?
The following method
ShowCameraGroupPopup
just shows/hides some tags I don't think it has much to do with the issue, but here it is anyways:function ShowCameraGroupPopup() { $('#<%=waitIcon.ClientID%>').show(); $('#<%=divMainContent.ClientID%>').hide(); $("#divCameraGroupPopup").modal("show"); return true; }
This is the flow after clicking the link button:
- Page_Load hit (is post back)
- btnCameraGroup_ServerClick hit
- Tab name = Second tab (this is the info I want, but for some reason the text isn't updated)
SOLVED: I needed an UpdatePanel (and ContentTemplate) around the TextBox with a Triggers (AsyncPostBackTrigger) as so:
<asp:UpdatePanel id="groupNamePanel" runat="server" updatemode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnCameraGroup" /> </Triggers> <ContentTemplate> <asp:TextBox id="locSelectedCameraGroupName" runat="server" ></asp:TextBox> </ContentTemplate> </asp:UpdatePanel>
解决方案If you have Page_Load() event in your codes, change Page_Load() content like below:
private void Page_Load() { if (!Page.IsPostBack) { //copy previous page load codes here } }
这篇关于点击一个按钮后更新文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!