• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 902
  • Last Modified:

use __doPostBack got error object expected

I'm useing __doPostBack  i don't know why it does not work  
I got error"object expected" this line    __doPostBack('btnDelete','');  
 anyone can help me
i'm useing studio2005
**********function comfirm and callpostback*************
function DeleteDataTest() {           
            var answer = confirm('Do you want to delete this user?')
            if (answer) {
                  __doPostBack('btnDelete','');                          
            }
        }

**********imgdelete in Repeater*******************
<img id="imgDelete" runat="server" alt="Delete" src="App_Themes/Default/images/delete2.png"
                                        style="width: 16px; height: 16px; cursor: pointer;" onclick="DeleteDataTest();"/>

*************button delete*****************************
 <asp:Button ID="btnDelete" runat="server" Text="delete" OnClick="btnDelete_Click" Visible="false" />

*************mothod btnDelete_Click *****************
protected void btnDelete_Click(object sender, EventArgs e)
    {
        lblerrorPw.Text = "xxx";
       // DeleteUser();
    }

Open in new window

0
aimds
Asked:
aimds
  • 7
  • 6
  • 5
  • +1
1 Solution
 
StealthyDevCommented:
I do think, you have removed, lblerrorPw label?
0
 
aimdsAuthor Commented:
no . it's still there .
<asp:Label ID="lblerrorPw" runat="server" Text="*" ForeColor="red"></asp:Label>
I have tried debug in btnDelete_Click and  it has never enter this method
even I have removed code all in btnDelete_Click  it still gave me the same error
0
 
bedanandCommented:
__doPostBack('btnDelete','');

btnDelete-> not corrent
should be clients id not server id.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
StealthyDevCommented:
Dear, you an option to execute a function in SERVER or in CLIENT.
The switch between them is runat="server".

If you leave it empty, you need to write the function in a script language like VB/Java.

See, in your code, you need to write a function named btnDelete_Click like this:

<script>
     function btnDelete_Click()
     {
          //your code.
     }
</script>

If you still want to run it in server, add this: (runat="server")

<asp:Button ID="btnDelete" runat="server" Text="delete" OnClick="btnDelete_Click" Visible="false"  runat="server"/>

Best regards.

0
 
masterpassCommented:
A small tweak would do the trick
**********function comfirm and callpostback*************
function DeleteDataTest() {           
    var answer = confirm('Do you want to delete this user?')
    var DeleteButton = document.getElementById('<%=btnDelete.ClientID %>');
    if (answer) {
          __doPostBack(DeleteButton,'');                          
    }
}

Open in new window

0
 
aimdsAuthor Commented:
btnDelete => this is clients ID and I need to run at server (btnDelete runat server)
2010-04-19-12-05-50.jpg
0
 
masterpassCommented:
You already had runat="server" in the HTML markup given in you question

<asp:Button ID="btnDelete" runat="server" Text="delete" OnClick="btnDelete_Click" Visible="false" />

By the way, Did you try my code ?
0
 
StealthyDevCommented:
Hi aimds,

as i have already prescribed you, add runat="server" to achieve this.

<asp:Button ID="btnDelete" runat="server" Text="delete" OnClick="btnDelete_Click" Visible="false"  runat="server"/>

Regards.
0
 
bedanandCommented:
pls check the client id of the btnDelete after you do the runat doing view source on the browser.

and replace here

 __doPostBack('newclientid','');  
0
 
aimdsAuthor Commented:
I tried verything you said
but i still got the same error
have tried this
<asp:Button ID="btnDelete" runat="server" Text="delete" OnClick="btnDelete_Click" runat="server"/>

tried this
function DeleteDataTest() {            
    var answer = confirm('Do you want to delete this user?')
    var DeleteButton = document.getElementById('<%=btnDelete.ClientID %>');
    if (answer) {
          __doPostBack(DeleteButton,'');                          
    }
}

and btnDelete is clientID the picture on my above comment is view source on the browser

this is my codes
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddUser.aspx.cs" Inherits="AddUser" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Administrator</title>
    <link href="App_Themes/Default/Default.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        function DeleteData(userid) {
            var hdfUserdelete = document.getElementById('hdfUserdelete');
            //hdfUserdelete.value = userid;   
            var answer = confirm('Do you want to delete this user?')
            if (answer) {
                  __doPostBack('btnDelete','');                          
            }
        }

        function DeleteDataTest() {           
             var answer = confirm('Do you want to delete this user?') 
                var DeleteButton = document.getElementById('<%=btnDelete.ClientID %>'); 
                if (answer) { 
                      __doPostBack(DeleteButton,'');                           
                } 
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="divmainUser">
        <div class="divtopuser">
            <table style="width:100%;">
            <tr>
            <td style="width:10%;font-weight:bold;">
                <asp:Label ID="lblerrorUser" runat="server" Text="*" ForeColor="red"></asp:Label>
                <asp:Label ID="lblusername" runat="server" Text="User Name"></asp:Label>
                </td>
            <td>
                <asp:TextBox ID="txtUsername" runat="server" Width="300"></asp:TextBox>
                </td>
            </tr>
            <tr>
            <td style="font-weight:bold;">
                <asp:Label ID="lblerrorPw" runat="server" Text="*" ForeColor="red"></asp:Label>
                <asp:Label ID="lblpw" runat="server" Text="Password"></asp:Label>
               </td>
            <td><asp:TextBox ID="txtPw" runat="server" Width="300" ></asp:TextBox>
            </td>
            </tr>
            <tr>
            <td></td>
            <td>            
                <asp:Label ID="lblresult" runat="server" Text="Label" ForeColor="red" Visible="false"></asp:Label><br />
                <asp:Button ID="btnSave" runat="server" Text="Save" Width="80" OnClick="btnSave_Click" /></td>
            </tr>
            </table>

            <br />
            <br />
        </div>
        <div class="divdetailuser">
          <table class="tableReater" cellspacing="0" cellpadding="5">
          <tr>
           <td class="ColumnPercent" style="height: 25px; width: 36%;">
               User Name
            </td>
            <td class="ColumnPercent" style="height: 25px; width: 20%;">
                Password
            </td>
            <td class="ColumnPercent" style="height: 25px; width: 4%;" >
                Delete
            </td>
          </tr>
            <asp:Repeater ID="rpUser" runat="server" OnItemDataBound="rpUser_ItemDataBound">
            <ItemTemplate>              
               <tr>
                <td >
                    <asp:Label ID="lbluser" runat="server" Text=<%#Eval("UserName") %>></asp:Label>
                </td>
                   <td>
                    <asp:Label ID="Label1" runat="server" Text=<%#Eval("Password") %>></asp:Label>
                    </td>
                <td align="center">
                    <img id="imgDelete" alt="Delete" src="App_Themes/Default/images/delete2.png"
                                        style="width: 16px; height: 16px; cursor: pointer;" onclick="DeleteDataTest();"/>
                                       <%-- <asp:ImageButton ID="ImageButton1" runat="server"                                        
                                        OnClick="ImageButton1_Click" ImageUrl="~/App_Themes/Default/images/delete2.png" 
                                         style="width: 16px; height: 16px; cursor: pointer;"/>--%>
                                    <span style="display: none;">
                                        <asp:HiddenField ID="hdfUserID" runat="server" />
                                    </span>
                </td>
                </tr>  
            </ItemTemplate>
            </asp:Repeater>
         </table>
        </div>
    </div>
        <br />
    <div>
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Login</asp:HyperLink>
        |
        <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/UploadFile.aspx">Upload File</asp:HyperLink>
        |
        <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/EditFile.aspx">Edit File</asp:HyperLink>
        <asp:HiddenField ID="hdfUserdelete" runat="server" />
        <div style="display:none;">
       <%--<asp:Button ID="btnDelete" runat="server" Text="delete" OnClick="btnDelete_Click"/>--%>
       <asp:Button ID="btnDelete" runat="server" Text="delete" OnClick="btnDelete_Click" runat="server"/>
       </div>
        </div>
    </form>
</body>
</html>

Open in new window

2010-04-19-13-20-09.jpg
0
 
bedanandCommented:
try this
function DeleteDataTest() {            
    var answer = confirm('Do you want to delete this user?') 
    if (answer) { 
          __doPostBack('<%=btnDelete.ClientID %>','');                           
    } 
}

Open in new window

0
 
StealthyDevCommented:
You need to write something like this in ,aspx.vb file

Or you just go to design view and double click the button.



Protected Sub btnDelete_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles BUTTON1.ServerClick
	runtestschoices.Visible = False
End Sub

Open in new window

0
 
aimdsAuthor Commented:
I have tried this but i still got the same error
function DeleteDataTest() {            
    var answer = confirm('Do you want to delete this user?')  
    if (answer) {  
          __doPostBack('<%=btnDelete.ClientID %>','');                            
    }  
}
i don't know why i have used the same codes on my another project it's work fine
but my another project is studi2008
this project  is studio2005
0
 
masterpassCommented:
Try this too
function DeleteDataTest() {            
    var answer = confirm('Do you want to delete this user?') 
    if (answer) { 
          __doPostBack('<%=btnDelete.UniqueID %>','');                           
    } 
}

Open in new window

0
 
aimdsAuthor Commented:
yes i have tried  still got the same error
function DeleteDataTest() {            
    var answer = confirm('Do you want to delete this user?')  
    if (answer) {  
          __doPostBack('<%=btnDelete.UniqueID %>','');                            
    }  
}

are there another way to call postback by script ?
0
 
masterpassCommented:
before we go to any other method, Try this too
function DeleteDataTest() {           
var answer = confirm('Do you want to delete this user?')
var DeleteButton = document.getElementById('<%=btnDelete.ClientID %>');
if (answer) {
   __doPostBack(DeleteButton.id,'');                          
}
}

Open in new window

0
 
bedanandCommented:
why dont use imagebutton instead of  

http://weblogs.asp.net/scottgu/archive/2006/01/02/434362.aspx

i assume you are using custom javascript to show confirm dailogbox.


<asp:ImageButton OnClientClick="return Confirm('do you want to delete');" ID="ImageButton1" runat="server"                                        
                                        OnClick="ImageButton1_Click" ImageUrl="~/App_Themes/Default/images/delete2.png" 
                                         style="width: 16px; height: 16px; cursor: pointer;"/>

Open in new window

0
 
aimdsAuthor Commented:
have tried this still same error
function DeleteDataTest() {            
var answer = confirm('Do you want to delete this user?')
var DeleteButton = document.getElementById('<%=btnDelete.ClientID %>');
if (answer) {
   __doPostBack(DeleteButton.id,'');                          
}
}

for this I don't know why  it did not give me any comfirm.
 only worked in ImageButton1_Click
<asp:ImageButton OnClientClick="return Confirm('do you want to delete');" ID="ImageButton1" runat="server"                                        
                                        OnClick="ImageButton1_Click" ImageUrl="~/App_Themes/Default/images/delete2.png"  
                                         style="width: 16px; height: 16px; cursor: pointer;"/>

0
 
masterpassCommented:
small change

<asp:ImageButton OnClientClick="javascript:return Confirm('do you want to delete');" ID="ImageButton1" runat="server"                                        
                                        OnClick="ImageButton1_Click" ImageUrl="~/App_Themes/Default/images/delete2.png"  
                                         style="width: 16px; height: 16px; cursor: pointer;"/>
0
 
bedanandCommented:
only worked in ImageButton1_Click

if this works for you. only postback occurs when you click yes o the confrimation window.

for masterpass:
OnClientClick="javascript:return Confirm('do you want to delete');"
i guess no need to put javascript. only required if you you put on href on conrol that generates a (anchor) tag.

0
 
aimdsAuthor Commented:
I added ScriptManager to the page and  now it's work fine
Thank you everyone for all help
but i still don't know why have to add ScriptManager ?
i did not use any ajax
 because i created AjaxEnableWebsite?
0
 
masterpassCommented:
Yes, ScriptManager is the super class (if I may say in Object oriented terms) when you use the Ajax enabled website.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 7
  • 6
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now