c# - 使用 JavaScript 检索文本框

标签 c# javascript gridview textbox

我有一个处于编辑模式的 GirdView,里面有一个 TextBox。

我需要在 JavaScript 中检索带有 ID 的 TextBox(从浏览器中的源代码)。

ctl00$MainContent$uxListOptions$ctl02$uxValueInput

但是我收到错误,因为我的 JavaScript 无法找到 TextBox。

这是代码:

   <span onclick="encodeMyHtml('<%# UniqueID.Replace("$", "_") %>_FormViewContentManager_ContentTextBox')">
        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="[Publish]" />
    </span>

在我的控件的 OnPageLoad 中,我称之为:

private void addEditorJavaScript()
{
    // create our HTML encoder javascript function
    // this way it shows up once per page that the control is on
    string scr = @"<script type='text/javascript'>function encodeMyHtml(name){
                var content = document.getElementById(name).value
                content = content.replace(/</g,'<');
                content = content.replace(/>/g,'>');
                document.getElementById(name).value = content;
            }</script>";

    // add the javascript into the Page
    ClientScriptManager cm = Page.ClientScript;
    cm.RegisterClientScriptBlock(this.GetType(), "GlobalJavascript", scr);
}

我正在尝试使用此代码 http://dustyreagan.com/how-to-submit-html-without-disabling/

知道我做错了什么吗?谢谢大家!

最佳答案

如果您使用的是 ASP.Net 4.0,则可以使用 ClientIdMode =此控件的静态或可预测。

关于c# - 使用 JavaScript 检索文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4582884/

相关文章:

javascript - 如何根据每个 item.id 的 NUM_PHOTOS 增加 .jpg 前缀的数字?

Javascript 函数indexOf 返回不正确的结果

c# - ASP :ImageButton OnClick event not firing in IE

c# - 我们可以用具有扩展方法的接口(interface)替换抽象类吗?

javascript - 我在这个 javascript 计算中做错了什么?

c# - 将列表数据绑定(bind)到 GridView。 GridView 找不到我的属性!

asp.net - 数据在 Gridview (ASP.NET) 中显示两次

c# - 俄罗斯方 block 游戏的记分牌 .txt 记分牌

c# - 需要一种方法来引用同一个第 3 方 DLL 的 2 个不同版本

c# - 如何将 ViewModel 属性绑定(bind)到转换器中的依赖属性