简体   繁体   中英

_doPostBack not definted in JavaScript

here is my ASP web Control

 <a id="geoLocation" class="geolocate box-outline active full">
            <div>
            <div class="icon"></div>
                <div class="header">
                 Locate Me Now
                    <asp:Label id="latitude" runat="server" ClientIdMode="Static"></asp:Label><br />

                    <asp:Label id="longitude" runat="server" ClientIdMode="Static"></asp:Label>
                    <div style="display:none">
                        <asp:Button ID="Button2" runat="server" Text="Button" ClientIdMode="Static" />
                    </div>
                </div>
                </div>
            </a> 

I am trying to do a Postback to be able to access the values of "longitude" and "latitude", in the code behind which I intend to make hidden.

this is the postback in Javascipt that I am using ... what am I doing wrong?

 function showPosition(position) {
        //  x.innerHTML = "Latitude: " + position.coords.latitude +
        // "<br>Longitude: " + position.coords.longitude;
          document.getElementById('latitude').innerHTML = position.coords.latitude;
          document.getElementById('longitude').innerHTML = position.coords.longitude;
          _doPostBack('#geoLocation', '');


}

First, make sure you have two underscores at the beginning of __doPostBack .

Second, the __doPostBack function is only available if at least one control on the page calls Page.RegisterPostBackScript() . Unfortunately, this method is internal to System.Web.

As a workaround, your control can override Render and call GetPostBackEventReference , which will call Page.RegisterPostBackScript() for you and return a bit of JavaScript that can be ignored:

protected override void Render(HtmlTextWriter writer)
{
    this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this));
    base.Render(writer);
}

Third (in answer to a question you haven't asked yet), setting the innerHTML property of a Label control will not make the value available to the server on postback. You should instead use a HiddenField control and set its value property in JavaScript.

Try this:

_doPostBack('#geoLocation', '');  -->   __doPostBack('#geoLocation', '');

You need two underscores at the beginning of the doPostBack method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM