I am creating a dynamic jobs list from a database that has conditional salary reporting based on union type. To handle the conditional statements I decided to build the dataset in the in the pageload section of the cs page for output to a label on the aspx page. All works as expected. The problem comes when I try to run JQuery or Javascripts on the HTML to collapse and expand the job titles to reveal the requirements. There are tons of way to do this in using JQuery, JS and Ajaxtookit. All work like a charm on static HTML. But .Net adds a span tag to my output which throws a wrench into the layout preventing the scripts from working. I then added a JQ function to remove the span tag then run the other scripts (all which I placed at the bottom of the page so they would get called after the page was loaded). Neither Document.ready or window.load had any effect. It appears that page load and page rendered states may be the issue. How can I get JQ and JS to see the html once it's written? Thanks
我正在从具有基于联合类型的条件工资报告的数据库创建动态作业列表。为了处理条件语句,我决定在cs页面的pageload部分中构建数据集,以输出到aspx页面上的标签。一切正常。当我尝试在HTML上运行JQuery或Javascripts以折叠和扩展作业标题以揭示需求时,问题就出现了。使用JQuery,JS和Ajaxtookit有很多方法可以做到这一点。所有工作都像静态HTML上的魅力。但.Net在我的输出中添加了一个span标记,这会在布局中引入一个扳手,阻止脚本工作。然后我添加了一个JQ函数来删除span标记,然后运行其他脚本(我放置在页面底部的所有脚本,以便在页面加载后调用它们)。 Document.ready或window.load都没有任何效果。看起来页面加载和页面呈现状态可能是问题。我怎样才能让JQ和JS在编写后看到html?谢谢
CS:
CS:
protected void Page_Load(object sender, EventArgs e)
{
String strConnString96 = WebConfigurationManager.ConnectionStrings["JobList_ConnectionString"].ConnectionString;
OleDbConnection con96 = new OleDbConnection(strConnString96);
OleDbCommand cmd96 = new OleDbCommand("SELECT * FROM JOBS WHERE (Status = 'Open') AND (Approved = 'Yes')", con96);
OleDbDataAdapter da96 = new OleDbDataAdapter(cmd96);
DataTable dtJobList = new DataTable();
da96.Fill(dtJobList);
con96.Close();
if (dtJobList == null || dtJobList.Rows.Count == 0)
lblJobList.Text = "<h3>No positions available at this time.</h3>";
if (dtJobList != null && dtJobList.Rows.Count > 0)
{
System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
int i = 0;
foreach (DataRow row in dtJobList.Rows)
{
string JobTitle = row["Job_Title"].ToString();
string Func = row["Functions"].ToString();
string Qual = row["Qualifications"].ToString();
string ReqNum = row["Req_Number"].ToString();
string Low = row["Low_Range"].ToString();
string High = row["High_Range"].ToString();
string SalType = row["Salary_Type"].ToString();
string Union = row["Union"].ToString();
i++;
sb1.Append("<div id='JobNbr-" + i + "'><h4>" + JobTitle + "</h4><h5>Essential Functions</h5><p>" + Func + "</p><h5>Qualifications</h5><p>" + Qual + "<p>");
if (Union == "Executive" || Union == "Local 6" || Union == "C93")
{
sb1.AppendLine("<h5>Starting Salary</h5><p>" + Low + " - " + High + " <i>(" + SalType + ")</i>");
}
else
{
sb1.AppendLine("<h5>Starting Salary</h5><p>" + High + " <i>(" + SalType + ")</i>");
}
sb1.AppendLine("<a href='/HR_WebForm/HR_Form.aspx?Req_Number=" + ReqNum + "&Job_Title=" + JobTitle + "'><img src='/Resources/icons/apply.gif' alt='Apply' /></a></p></div>");
lblJobList.Text = sb1.ToString();
}
}
}
ASPX:
ASPX:
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolderMain" runat="server">
<h1>Employment</h1>
<div id="Employment">
<h2>Join New England's largest retail water & sewer provider!</h2>
<h2>How to Apply:</h2>
<ol><li>Submit your resume and cover letter online, please send attachments in PDF or Microsoft Word format, if not please fax to 617-989-7754 OR</li>
<li>Visit our Human Resources Department at 980 Harrison Avenue Boston, MA 02119</li></ol>
<p>We are located on several MBTA bus routes and visitors' parking is available on-site. Our office is open Monday through Friday, 8:00AM to 5:00PM.
</p>
<p>Come join our team!</p>
<h2>Current Openings</h2>
<div id="CurrentOpenings">
<a id="On" name="On" onclick="openAll('CurrentOpenings', 'h4','');" href="#_" class="hideIfNoJS">Open All</a>
<a id="Off" name="Off" onclick="closeAll('CurrentOpenings', 'h4','');" href="#_" class="hideIfNoJS">Close All</a>
<asp:Label ID="lblJobList" runat="server" Text="Label" />
</div>
<script>window.onload = "setCollapseExpand('CurrentOpenings', 'h4',''); revealControl('On'); revealControl('Off');"</script>
<script type="text/javascript" src="/JScode/expandcollapse.js"></script>
</asp:Content>
1 个解决方案
#1
0
You are setting window.onload to a string.
您正在将window.onload设置为字符串。
window.onload = "setCollapseExpand('CurrentOpenings', 'h4',''); revealControl('On'); revealControl('Off');"</script>
It is expecting a function. Since you tagged this jquery, use it.
它期待一个功能。由于您标记了此jquery,请使用它。
$(window).on("load", function () {
setCollapseExpand('CurrentOpenings', 'h4','');
revealControl('On');
revealControl('Off');
});
#1
0
You are setting window.onload to a string.
您正在将window.onload设置为字符串。
window.onload = "setCollapseExpand('CurrentOpenings', 'h4',''); revealControl('On'); revealControl('Off');"</script>
It is expecting a function. Since you tagged this jquery, use it.
它期待一个功能。由于您标记了此jquery,请使用它。
$(window).on("load", function () {
setCollapseExpand('CurrentOpenings', 'h4','');
revealControl('On');
revealControl('Off');
});