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

时间:2018-02-23 07:05:52

标签: javascript c# html asp.net ajax

我有一个包含2个主要“div”的网页表单。在第一个div(DivUser)中,我有一个包含文本框和按钮的表单,在第二个div(DivSignature)中,我从该表单中获取值并显示在第二个div,当我点击表格中的btn_CreateSignature按钮。 我想避免刷新第一个div中的文本框值,但我想刷新第二个div。 我怎么能这样做?我在下面添加了我的代码。请帮我解决这个问题。

提前致谢。

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

1 个答案:

答案 0 :(得分:1)

好的,先改变

<input> 

标记为

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

现在在.cs(或.vb)文件中,您将这些文本框的所有值保存到会话状态。

Session["SessionName"] = textBox1.Text;

之后,您将填充Page_Load方法中的控件:

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

如果有多个TextBox存储数组中的值,然后将数组存储在会话中,则可以。

希望这会有所帮助;)