从jquery访问asp.net Web服务器控件

时间:2021-01-09 15:52:47

In my C# asp.net 3.5 web application I am having controls like div tag inside that one textbox and one check box and the page is having a submit button. So in this submit button click I want to make the controls inside the div tag visible.. I am calling a JQuery function to do this. All the statements are getting executed but the control is not visible.. Following is the code in my JQuery function

在我的C#asp.net 3.5 Web应用程序中,我在一个文本框和一个复选框内有div标签等控件,页面上有一个提交按钮。所以在这个提交按钮单击我想让div标签内的控件可见..我正在调用一个JQuery函数来执行此操作。所有语句都被执行但控件不可见。以下是我的JQuery函数中的代码

$("input[name$='QuestionAndAnswerEditorDiv']").show();
$("input[name$='answerLabel1']").show()
$("input[name$='wmd-AnswerTextBox']").show() 

My div tag and its controls in the user control page are like the following

我的div标签及其在用户控制页面中的控件如下所示

 <div id="QuestionAndAnswerEditorDiv" runat="server">
 <div id="wmd-button-bar" class="wmd-panel wmd-button-row"></div> 
 <textarea name="QuestionandAnswerTextArea" runat="server" id="AnswerTextBox" onkeyup="prettyPrint();" class="wmd-input editor" cols="92" rows="15"/><div class="wmd-preview text-preview preview" style="-ms-word-wrap: break-word;"></div>

As I noticed these controls are make visible=false in another page so they are not coming in the page source.. So Let me know how to work these controls now

我注意到这些控件在另一个页面中显示为visible = false,因此它们不会进入页面源..所以现在让我知道如何使用这些控件

3 个解决方案

#1


1  

all web server controls in asp.net < 4 are not rendered using their given name. to use the rendered name use Control.ClientID

asp.net <4中的所有Web服务器控件都不使用其给定名称进行呈现。使用呈现的名称使用Control.ClientID

#2


1  

Setting QuestionAndAnswerEditorDiv.Visible = false; will mean that it doesn't get rendered to the page. In your code behind do the following:

设置QuestionAndAnswerEditorDiv.Visible = false;意味着它不会被渲染到页面。在您的代码后面执行以下操作:

QuestionAndAnswerEditorDiv.Attributes.Add("style", "display:none");
QuestionandAnswerTextArea.Attributes.Add("style", "display:none");

the JQuery show() function uses the display property and will set it to "block", which will make it visible.

JQuery show()函数使用display属性并将其设置为“block”,这将使其可见。

#3


0  

This may not work because div is not going to render as input element and label is rendered as span element in asp.net so check for the type of controls

这可能不起作用,因为div不会呈现为输入元素,标签在asp.net中呈现为span元素,因此请检查控件的类型

for div
$("div[name$='QuestionAndAnswerEditorDiv']").show();

for label
$("span[name$='answerLabel1']").show()

for textbox
$("input[name$='wmd-AnswerTextBox']").show() 

Edit :

so as i suggested in my answer make use of proper jquery selctor so that this will work for you

所以我在我的回答中建议使用正确的jquery selctor,以便这对你有用

Edit 1

So rather than making control visible= false set there sytles to disply:none so that controls avaialbe on you page and you can play with them using jquery/javascript

所以,而不是让控制可见= false设置sysh to disply:none以便控制avaialbe在你的页面上你可以使用jquery / javascript来玩它们

#1


1  

all web server controls in asp.net < 4 are not rendered using their given name. to use the rendered name use Control.ClientID

asp.net <4中的所有Web服务器控件都不使用其给定名称进行呈现。使用呈现的名称使用Control.ClientID

#2


1  

Setting QuestionAndAnswerEditorDiv.Visible = false; will mean that it doesn't get rendered to the page. In your code behind do the following:

设置QuestionAndAnswerEditorDiv.Visible = false;意味着它不会被渲染到页面。在您的代码后面执行以下操作:

QuestionAndAnswerEditorDiv.Attributes.Add("style", "display:none");
QuestionandAnswerTextArea.Attributes.Add("style", "display:none");

the JQuery show() function uses the display property and will set it to "block", which will make it visible.

JQuery show()函数使用display属性并将其设置为“block”,这将使其可见。

#3


0  

This may not work because div is not going to render as input element and label is rendered as span element in asp.net so check for the type of controls

这可能不起作用,因为div不会呈现为输入元素,标签在asp.net中呈现为span元素,因此请检查控件的类型

for div
$("div[name$='QuestionAndAnswerEditorDiv']").show();

for label
$("span[name$='answerLabel1']").show()

for textbox
$("input[name$='wmd-AnswerTextBox']").show() 

Edit :

so as i suggested in my answer make use of proper jquery selctor so that this will work for you

所以我在我的回答中建议使用正确的jquery selctor,以便这对你有用

Edit 1

So rather than making control visible= false set there sytles to disply:none so that controls avaialbe on you page and you can play with them using jquery/javascript

所以,而不是让控制可见= false设置sysh to disply:none以便控制avaialbe在你的页面上你可以使用jquery / javascript来玩它们