I have a div
in which user insert SQL
query and I want to access this query in codebehind
and pass to sqlcmd
and execute query and show result to user but I'm unable to do this. How can I do this? Here is my aspx code:
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
<form id="form1" runat="server">
<div id="editor" contenteditable="true"></div>
<br />
<asp:Button runat="server" OnClick="load" Text="Submit" />
<asp:label ID="TextBox1" ForeColor="White" runat="server"></asp:label>
</form>
</asp:Content>
my aspx.cs (codebehind) is :
public void load(object sender, EventArgs e)
{
HtmlGenericControl footer = (HtmlGenericControl)FindControl("editor");
String cmd = footer.InnerHtml.ToString();
TextBox1.Text = cmd;
}
将runat =“ server”添加到您的DIV标签中,它将解决您的问题。
<div id="editor" contenteditable="true" runat="server"></div>
Add runat="server"
in div like this:-
<div id="editor" contenteditable="true" runat="server">Lorem Ipsum</div>
and use this code
protected void Page_Load(object sender, EventArgs e)
{
ContentPlaceHolder mainContent = (ContentPlaceHolder)this.Master.FindControl("body");
HtmlGenericControl footer = (HtmlGenericControl)mainContent.FindControl("editor");
String cmd = footer.InnerHtml.ToString();
TextBox1.Text = cmd;
}
where body
is ContentPlaceHolderID
you can find this on your content page
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
Hope this will help you
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.