简体   繁体   中英

Copy HTML textbox value from ContentPlaceHolder2 to asp.net textbox value on ContentPlaceHolder1

I need to copy HTML textbox value from ContentPlaceHolder2 to and ASP.NET textbox value on ContentPlaceHolder1.

The reason for that I need to pass this asp.net textbox as a parameter for a storedprocedure on ContentPlaceHolder1 (Which I can't do it from ContentPlaceHolder2)

I have tried to do that with in code bedind using Request.Form but it didn't work. I think because the button control can't access ContentPlaceHolder2?

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:Button ID="btnCopyIng" runat="server" OnClientClick="Copy()" OnClick="btnCopyIng_OnClick" Text="Copy" />
    <asp:TextBox ID="txtIngredientName" runat="server"></asp:TextBox>
    <input id="txtIngValue" name="Ing Value" type="text" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <strong>Ingredient Name: </strong>
    <input id="txtIngName_new" type="text" onkeyup="sync()" kendo-text-box="txtIngName" class="k-input k-textbox TextCtrlReqBgImage" name="Ingredinet name" style="width: 350px;" required="required" ng-click="txtIngNameClick()" ng-readonly="ingNameReadOnly" ng-model="selectedIng.Ingredients_Name">
</asp:Content>

Code Behind:

protected void btnCopyIng_OnClick(object sender, EventArgs e)
{
    string name = Request.Form["Ingredinet name"].ToString();
    txtIngredientName.Text = name; 
}

You can use jQuery, you have already created the reference to an OnClientClick function callled Copy anyway

function Copy() {

$(‘<%= txtIngredientName.ClientID %>’).val($(‘#txtIngName_new’).val());

}

I think this will work from the code behind, get the text from txtIngredientName and set the text for txtIngName_new:

protected void btnCopyIng_OnClick(object sender, EventArgs e)
{
     txtIngName_new.Text = txtIngredientName.Text; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM