简体   繁体   English

单击按钮时如何避免刷新asp.net中的文本框值?

[英]How to avoid refreshing of textbox value in asp.net when click button?

I have a web form that includes 2 main "div".In first div(DivUser),i have a form that includes textboxes and buttons and in the second div(DivSignature),i get the values from that form and show at the second div when i click on the btn_CreateSignature button in form. 我有一个包含2个主要“ div”的Web表单。在第一个div(DivUser)中,我有一个包含文本框和按钮的表单,在第二个div(DivSignature)中,我从该表单获取值并在第二个中显示当我单击窗体中的btn_CreateSignature按钮时的div。 I want to avoid refreshing of the textboxes' value in first div but i want to refresh the second div. 我想避免在第一个div中刷新文本框的值,但我想刷新第二个div。 How can i do that?I have added my code below.Please help me about that issue. 我该怎么做?我在下面添加了我的代码。请帮助我解决该问题。

Thanks in advance. 提前致谢。

 <body> <form id="form1" runat="server"> <div id="DivUser" class="y-container Outer"> <div class="jumbotron"> <asp:ScriptManager runat="server" ID="ScriptManager" /> <asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional" RenderMode="Block"> <ContentTemplate> <h5>Hello <asp:LinkButton ID="lblUserName" ForeColor="Red" runat="server">LinkButton</asp:LinkButton></h5> </ContentTemplate> </asp:UpdatePanel> <h5><asp:LinkButton ID="btnLogOut" runat="server" ForeColor="Red" CssClass="pull-right" OnClick="btnLogOut_Click" Font-Underline="True">Log Out</asp:LinkButton> </h5> <h2><asp:Label ID="lblUser" runat="server" ForeColor="Red"/> - Update User Information</h2> </div> <div class="form-group row InnerLeft" style="margin-left:5px;margin-top:10px;" > <div class="form-inline form-group"> <label class="col-2 col-form-label">User Name</label> <input class="form-control col-10" type="text" id="inputUsername" style="width:22%;font-size:16px;" runat="server" required="required"/> </div> <div class="form-inline form-group"> <label class="col-2 col-form-label">Name</label> <input class="form-control col-10" type="text" id="inputName" style="margin-left:75px;width:22%;font-size:16px;" runat="server" required="required"/> </div> <div class="form-inline form-group"> <label class="col-2 col-form-label">Surname</label> <input class="form-control col-10" type="text" id="inputSurname" style="margin-left:48px;width:22%;font-size:16px;" runat="server" required="required"/> </div> <div class="form-inline form-group"> <label class="col-2 col-form-label">Title</label> <input class="form-control col-10" type="text" id="inputTitle" style="margin-left:48px;width:42%;font-size:16px;" runat="server" required="required"/> </div> <div class="form-inline form-group"> <label class="col-2 col-form-label">Email</label> <input class="form-control col-10" type="email" id="inputEmail" style="margin-left:52px;width:42%;font-size:16px;" runat="server" required="required"/> </div> <div class="form-inline form-group"> <label class="col-2 col-form-label">Phone</label> <input class="form-control col-10" type="tel" id="inputPhone" style="margin-left:40px;width:22%;font-size:16px;" runat="server" required="required"/> </div> <label class="col-2 col-form-label">Update Password</label> <asp:Button ID="btn_UpdatePassword" class="btn btn-success" runat="server" OnClick="btn_UpdatePassword_Click" Text="Update Password"/> <p /><br /> <label class="col-2 col-form-label">Create Signature</label> <asp:Button ID="btn_CreateSignature" class="btn btn-warning leftmargin" runat="server" OnClick="btn_CreateSignature_Click" Text="Create Signature"/> <p /><br /> <asp:Button ID="btn_Update" class="btn btn-primary" Text="Update" runat="server" OnClick="btn_Update_Click" />&nbsp; <asp:Button ID="btn_Cancel" class="btn btn-primary" Text="Cancel" OnClick="btn_Cancel_Click" runat="server"/> </div> <div class="InnerRight" style="width:425px;height:260px;"> <div id="divSignature" class="x-container" style="margin-top:10px;padding-top:10px; width:425px;height:260px;background-color:White;"> <div class="row"> <div> <img style="width: 140px" src="images/logo_signature.png"/> </div> <div style="margin-left: 15px"> <div class="x-container"> <div class="row"> <div> <div class="x-container"> <div class="row"> <h5> <strong><asp:Label ID="lblName" runat="server" style="font-family:'Times New Roman'"></asp:Label></strong> </h5> </div> <div class="row" style="margin-top: -10px"> <p> <asp:Label ID="lblTitle" runat="server" style="font-family:'Times New Roman'"></asp:Label> </p> </div> <hr style="margin-top: -10px;"/> <div class="row" style="margin-top: -15px"> <p> <strong>M&nbsp;:</strong><p> <asp:Label ID="lblPhone" runat="server" style="font-family:'Times New Roman'"></asp:Label></p> </p> </div> <div class="row" style="margin-top: -20px"> <p> <strong>T&nbsp;&nbsp;: </strong><p style="font-family:'Times New Roman'"> +00 000 00 00</p> </p> </div> <div class="row" style="margin-top: -20px"> <p> <strong>E &nbsp;:&nbsp;</strong><p> <asp:Label ID="lblEmail" runat="server" style="font-family:'Times New Roman'"></asp:Label> </p> </p> </div> <div class="row" style="margin-top: -20px"> <p> <strong>W:&nbsp;</strong><p style="font-family:'Times New Roman'"> www.website.com</p> </p> </div> </div> </div> </div> </div> </div> </div> <div class="row" style="margin-top: 0px; margin-left: 1px;font-size:12px;"> <div class="x-container"> <div class="row"> <div style="align-self: center;font-family:'Times New Roman'" > Address<br/> </div> <div style="margin-left: 15px;"> <img width="70" src="images/qr_code.png"/> </div> </div> </div> </div> <div class="row" style="margin-top: 0px; margin-left: 0px" > <img style="width: 400px" src="images/seritt.png"/> </div> </div> </div> </div> </form> </body> 

Ok, First change the 好,先更改

<input> 

tags to 标签到

<asp:textbox id="controlID" runat="server"> 

now in the .cs (or .vb) file you will save all the values of these textbox to a session state. 现在,在.cs(或.vb)文件中,您会将这些文本框的所有值保存为会话状态。

Session["SessionName"] = textBox1.Text;

And after that you will fill the controls in the Page_Load method: 之后,您将在Page_Load方法中填充控件:

if(!isPostBack){
 textBox1.Text = Session["SessionName"];
}

You can, if you have more than one TextBox store the values in an array and then store the array in a session. 如果您有多个TextBox,则可以将值存储在一个数组中,然后将其存储在会话中。

hope this helps ;) 希望这可以帮助 ;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击asp.net中的按钮时如何避免TextBox失去焦点 - How to avoid lost focus of TextBox when click a button in asp.net 如何通过单击一次按钮保存asp.net文本框值,并将该数据用于另一次单击按钮? - How to save asp.net textbox values with one button click and use that data for another button click? 在用户控件中单击ASP.NET时,可以使用javascript在主页中设置文本框的值 - ASP.NET on button click in user control set the value of a textbox in the main page using javascript Asp.Net 在按钮单击时将值从 GridView 传递到模态文本框 - Asp.Net Pass value to Modal TextBox from GridView on button click 当我单击asp.net中的退出按钮时,不会触发textbox onblur事件 - textbox onblur event not fired when i click the exit button in asp.net 从asp.net文本框回发取消按钮单击事件 - Postback from asp.net textbox cancels button click event 在asp.net上单击按钮的空文本框的Javascript验证 - Javascript validation for empty textbox on button click in asp.net Javascript-ASP.Net上的文本框验证按钮单击 - Javascript - textbox validation on ASP.Net button click 如何仅在用户单击提交表单时触发数据验证,而不是在 ASP.NET MVC 中的文本框中更改值后触发数据验证? - How to trigger data validation only when user click on submit form but not after value changing in textbox in ASP.NET MVC? 用户使用JQuery切换到Asp.net文本框值时,如何用它替换以前的asp.net文本框值? - How can I fill an asp.net textbox with a previous asp.net textbox value when the user tabs to it using JQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM