Link to home
Start Free TrialLog in
Avatar of JB4375
JB4375Flag for United States of America

asked on

MS Jscript runtime error: Object doesn't support this property of method.

I have a ASP.Net form that uses JScript to send a popup message when the text fields are left blank. I've used this code a least 10 times but on this time it seems to have a problem with this line which I've been using nearly as long: Page.MaintainScrollPositionOnPostBack = True

I noticed during testing that my page was loading but doing so with errors. I started the debug process and came up with the following:

Code sections and error messages below.

Thanks!!
VB Backend Page:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.MaintainScrollPositionOnPostBack = True
        strAudixNeed = "No"
        strRushNeed = "No"
        strWiringNeed = "No"
        strDate = Now
        strUser = (Request.ServerVariables("AUTH_USER"))
        If InStr(strUser, "domain\") Then
            strUser = Replace(strUser, "domain\", "")
        End If
        If InStr(strUser, "domain\") Then
            strUser = Replace(strUser, "domain\", "")
        End If
        Label48.Text = "domain\" & strUser

    End Sub

JSCRIPT Sub to Send Message:

    Public Sub UserMsgBox(ByVal F As Object, ByVal sMsg As String)
        Dim sb As New StringBuilder()
        Dim oFormObject As System.Web.UI.Control = Nothing
        Try
            sMsg = sMsg.Replace("'", "\'")
            sMsg = sMsg.Replace(Chr(34), "\" & Chr(34))
            sMsg = sMsg.Replace(vbCrLf, "\n")
            sMsg = "<script language='javascript'>alert('" & sMsg & "');</script>"
            sb = New StringBuilder()
            sb.Append(sMsg)
            For Each oFormObject In F.Controls
                If TypeOf oFormObject Is HtmlForm Then
                    Exit For
                End If
            Next
            oFormObject.Controls.AddAt(oFormObject.Controls.Count, New LiteralControl(sb.ToString()))
        Catch ex As Exception
        End Try
    End Sub

form.aspx[dynamic]  ***Occurs during debug process***

<script type="text/javascript">
//<![CDATA[

theForm.oldSubmit = theForm.submit;
theForm.submit = WebForm_SaveScrollPositionSubmit;

theForm.oldOnSubmit = theForm.onsubmit;
theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit;
Sys.Application.initialize();
//]]>
<

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you have partial rendering enable on the page?

"MaintainScrollPostition is not supported on pages with partial rendering turned on"
Avatar of JB4375

ASKER

No... no partial rendering.
In researching I saw where some of this could be handled via AJAX and I don't have that.
I also saw code for it in Javascript, but the only the only place that it exists is in the sub that I referenced above.
Avatar of JB4375

ASKER

Anyone got another suggestion?
Avatar of JB4375

ASKER

I've been testing this for a while and I've come up with some interesting situations.
First, the IF statements weren't that well formed, and I've redone those to produce more desirable results.
Second, if I set the dropdownlist autopostback="false" I can click submit, and because some of the form in still imcomplete it produces my message to complete the form, but  the text boxes populate correctly and no javascript error is produced.
Third, if I set the DDL autopostback="true" and select an option from it the javascript error is produced, and clicking submit again produces my message but also clears the javascript error.
Finally:
Viewing Source with APB="False" shows this:
    <form name="form1" method="post" action="form.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2NTcyMDU2OTAPZBYCAgMPZBYKAisPEGRkFgFmZAJfDw8WAh4HVmlzaWJsZWhkZAJhDw8WAh8AaGRkAmMPDxYCHwBoZGQCaw8PFgIeBFRleHQFD21lZGN0clxtaGJvd21hbmRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYDBQpDaGVja0JveDE0BQpDaGVja0JveDE1BQpDaGVja0JveDE2RqjaN1Nsa8jJg+fPR0j1BzdFJyU=" />
</div>
<div>
 <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWIQK02c+8DwLs0bLrBgLs0fbZDALs0Yq1BQLs0e58AuzRgtgJAuzRxsYPAuzR2qEIAvKJkN4OAtfN8vACAsu8pOwDApzX4pwNAp7szM0JAtWv9ZwNApTP1bcBAr2tm40PAv+D0vsCAsHzqacFAsON7+UMAqHw554IAo3t9PMHAqrU7OEDAqvU7OEDAqzU7OEDAoLkp7wJAoLkq7wJAoLkn7wJArDU7OEDAqHU7OEDAqLU7OEDAv+x2Y4EAtLzIQLcu4S2BBMVsvhKr2+j0ZYSRIqw+TnBkAZk" />
</div>
Viewing Source with APB="True" shows:

<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2NTcyMDU2OTAPZBYCAgMPZBYKAisPEGRkFgFmZAJfDw8WAh4HVmlzaWJsZWhkZAJhDw8WAh8AaGRkAmMPDxYCHwBoZGQCaw8PFgIeBFRleHQFD21lZGN0clxtaGJvd21hbmRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYDBQpDaGVja0JveDE0BQpDaGVja0JveDE1BQpDaGVja0JveDE2RqjaN1Nsa8jJg+fPR0j1BzdFJyU=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();   ******** This is where it blows up *****************************
    }
}
//]]>
</script>

<div>
 <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWIgK02c+8DwLs0bLrBgLs0fbZDALs0Yq1BQLs0e58AuzRgtgJAuzRxsYPAuzR2qEIApTkj+UKAvKJkN4OAtfN8vACAsu8pOwDApzX4pwNAp7szM0JAtWv9ZwNApTP1bcBAr2tm40PAv+D0vsCAsHzqacFAsON7+UMAqHw554IAo3t9PMHAqrU7OEDAqvU7OEDAqzU7OEDAoLkp7wJAoLkq7wJAoLkn7wJArDU7OEDAqHU7OEDAqLU7OEDAv+x2Y4EAtLzIQLcu4S2BCeIMEkTpaX6M0xNuOzNv9i7wVTy" />
</div>
Can anyone tell me why this is blowing up when I have another page that uses this exact same code on another page with no issues??
Thanks!!

<div class="column1">
<asp:Label ID="Label10" runat="server" Text="RequestType:"></asp:Label><br />
<asp:DropDownList ID="DropDownList8" tabindex="8" runat="server" AutoPostBack="true" Width="200px">		                <asp:ListItem Value="Select Type">Select Type</asp:ListItem>
<asp:ListItem>Install</asp:ListItem>
<asp:ListItem>Move</asp:ListItem>
<asp:ListItem>Upgrade</asp:ListItem>
</asp:DropDownList> 
</div><!-- end class column1-->

Protected Sub DropDownList8_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList8.SelectedIndexChanged
        If DropDownList8.SelectedItem.Text = "Move" Then
            TextBox11.Text = "Not Applicable"
            TextBox13.Text = "Not Applicable"
        ElseIf DropDownList8.SelectedItem.Text = "Upgrade" Then
            TextBox11.Text = "Not Applicable"
            TextBox13.Text = ""
        Else
            TextBox11.Text = ""
            TextBox13.Text = ""
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JB4375
JB4375
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial