IE未在文字文本</form>中显示<form>标记

时间:2010-01-05 06:38:14

标签: asp.net html internet-explorer

我在我的页面上使用了一个文字,里面有一个html表单。单击特定链接时会显示此文字,页面上会显示叠加div,并在叠加div上显示该表单。所有浏览器都能正常工作并且完全符合预期,但是IE在叠加div上没有显示任何内容,即叠加div显示但是为空。我已经尝试逐个向文字控件添加标签,以查看究竟是哪个标签导致了问题,并且结果显示所有内容(HTML输入控件等)都显示在叠加div上,直到<form>标记为在文字中添加。
如果literal.Text属性没有<form>标记,则内容在IE中也会显示正常。但问题是我需要在文字内部使用<form>,因为我必须将数据发布回外部链接。当所有其他浏览器都正常工作时,IE中的问题可能是什么?

以下是其设置时的文字内容:

formSalesForce.Text = "<div style='clear:both'></div><h2 class='sIFR-replaced1' style='text-align:left'><embed height='20'  id='h2heading' width='282' src='frutiger_light.swf' quality='best' flashvars='txt=Document Description&amp;textalign=left&amp;offsetTop=0&amp;textcolor=#878787&amp;hovercolor=#76b404&amp;linkcolor=#87be22&amp;w=282&amp;h=20' wmode='transparent' bgcolor='transparent' sifr='true' type='application/x-shockwave-flash' class='sIFR-flash1' style='width: 282px; height: 20px;'/><span class='sIFR-alternate'>Document Description</span></h2>" + d.DocDescription + "<BR><p>Please fill out the following information so that we can proceed with providing you the link to the document</p><form  id='myDocForm' name='myDocForm' action='" + d.DataSubmissionPath + "' method='POST' ><table class='clearBoth' width='45%'><tr><td><input type=hidden name='oid' value='" + d.OID + "'></td><td><input type=hidden name='retURL' value='" + "" + "'></td></tr><tr><td class='formlabel' >First Name*</td><td class='formfield'><input type='text' id='first_name' size='20' maxlength='40' name='first_name'></td></tr><tr><td class='formlabel'>Last Name*</td><td class='formfield'><input type='text' id='last_name' size='20' maxlength='40' name='last_name'></td></tr><tr><td class='formlabel'>Email*</td><td class='formfield'><input type='text' id='email' size='20' maxlength='40' name='email'></td></tr><tr><td class='formlabel'>Work Title</td><td class='formfield'><input type='text' id='work_title' size='20' maxlength='40' name='work_title'></td></tr><tr><td class='formlabel'>Company</td><td class='formfield'><input type='text' id='company' size='20' maxlength='40' name='company'></td></tr><tr><td class='formbuttons'><input type='Button' name='btnsubmit' value='Submit' onclick='showDocPanel();'></td></tr></table></form>"

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

我必须执行以下解决方法:

我使用Request.Browser.Browser来检查浏览器是否是IE ...然后我将文字文本修改为以下内容:

 Dim s As New StringBuilder
    s.Append("<iframe name='myIframe' style='visibility:hidden;height:0;width:0;'></iframe><div style='clear:both'></div><h2 class='sIFR-replaced1' style='text-align:left'><embed height='20'  id='h2heading' width='282' src='swf/frutiger_light.swf' quality='best' flashvars='txt=Document Description&amp;textalign=left&amp;offsetTop=0&amp;textcolor=#878787&amp;hovercolor=#76b404&amp;linkcolor=#87be22&amp;w=282&amp;h=20' wmode='transparent' bgcolor='transparent' sifr='true' type='application/x-shockwave-flash' class='sIFR-flash1' style='width: 282px; height: 20px;'/><span class='sIFR-alternate'>Document Description</span></h2><p align='left'><i>" + d.DocDescription + "</i><BR><BR></p>")
    s.Append("<p>Please fill out the following information so that we can proceed with providing you the link to the document</p>")
    If (Not Request.Browser.Browser.Equals("IE")) Then
        s.Append("<form  id='myDocForm' name='myDocForm' target='myIframe' action='" + d.DataSubmissionPath + "' method='POST' >")
    End If

    s.Append("<table class='clearBoth' width='45%'><tr><td>")
    s.Append("<input type=hidden name='oid' id='oid' value='" + d.OID + "'></td><td>")
    s.Append("<input type=hidden name='retURL'  id='retURL' value='" + "" + "'></td></tr>")

    ' debug(info)
    s.Append("<input type='hidden' name='debug' value=1>")
    s.Append("<input type='hidden' name='debugEmail'")
    s.Append("value=''>")

    s.Append("<tr><td class='formlabel'>First Name*</td>")
    s.Append("<td class='formfield'><input type='text' id='first_name' size='20' maxlength='40' name='first_name'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Last Name*</td>")
    s.Append("<td class='formfield'><input type='text' id='last_name' size='20' maxlength='40' name='last_name'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Email*</td>")
    s.Append("<td class='formfield'><input type='text' id='email' size='20' maxlength='40' name='email'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Work Title</td>")
    s.Append("<td class='formfield'><input type='text' id='work_title' size='20' maxlength='40' name='work_title'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Company</td>")
    s.Append("<td class='formfield'><input type='text' id='company' size='20' maxlength='40' name='company'>")
    s.Append("</td></tr>")
    s.Append("<tr><td>&nbsp;</td>&nbsp;<td></td></tr>")     'empty row for spacer cells
    s.Append("<tr><td>&nbsp;</td><td class='formbuttons'  align='right'><input type='Button' id='btnsubmit' name='btnsubmit' value='Submit' onclick='showDocPanel();'>")
    s.Append("</td></tr>")
    s.Append("</table>")
    If (Not Request.Browser.Browser.Equals("IE")) Then
        s.Append("</form>")
    End If
formSalesForce.Text=s.ToString()

所以IE浏览器显示了表格,因为在使用IE时,文字没有附加标签。

现在;在使用IE时,我有一个问题是将表单发布到外部网站,因为没有表单,它无法提交...因此我不得不使用由javascript创建的重复表单:

使用从此网站获取的此javascript片段:http://en.allexperts.com/q/Javascript-1520/create-form-submit-fly.htm

 function getNewSubmitForm(){
 var submitForm = document.createElement("FORM");
 document.body.appendChild(submitForm);
 submitForm.method = "POST";
 return submitForm;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
 var newElement = document.createElement("<input name='"+elementName+"' id='" + elementName + "' type='hidden'>");
 inputForm.appendChild(newElement);
 newElement.value = elementValue;
 return newElement;
}

//function that creates the form, adds some elements
//and then submits it
function createFormAndSubmit(){
var submitForm = getNewSubmitForm();
//alert("form created");
createNewFormElement(submitForm, "oid", document.getElementById("oid").value);
createNewFormElement(submitForm, "debug", "1");
createNewFormElement(submitForm, "debugEmail", "");
createNewFormElement(submitForm, "first_name", document.getElementById("first_name").value);
createNewFormElement(submitForm, "last_name", document.getElementById("last_name").value);
createNewFormElement(submitForm, "email", document.getElementById("email").value);
createNewFormElement(submitForm, "work_title", document.getElementById("work_title").value);
createNewFormElement(submitForm, "company", document.getElementById("company").value);
createNewFormElement(submitForm, "retURL", window.location.href);
//alert(window.location.href + "::elements added");
submitForm.action= "my external website url";
submitForm.target='myIframe';
//alert("submitting");
submitForm.submit();
}

现在,当表单提交到外部网址时发生了回发,我在周围工作:

  • 创建了一个隐藏的iframe并将其附加到文字文本中(请参阅上面的文字文字代码)
  • 将表单目标设置为该帧的名称(请参阅上面的文字文本代码)
  • 将重复的javascript表单的目标设置为该帧的名称(请参阅上面的javascript代码)

答案 2 :(得分:0)

将表格边距设置为零也应该有效:

.formStyle { 保证金:0px; }