Solved

__doPostBack Not Working

Posted on 2008-06-18
2
2,112 Views
Last Modified: 2008-10-08
Hi Experts,
    I have a problem Im hoping someone here can help me out here with. I am trying to use an imageButton to call the click event of a link button by doing a forced postback. This should be a simple task, but I have had no luck with this, and am stuck. The code for both the aspx file including the javascript function and the codebehind for the LinkButton_Click event is also posted. Any help to solve this would be appreciated. Thanks in Advance


ASPX
 
 <script type="text/javascript">
    function FillText()
    {
    //debugger;
      __doPostBack('<%= LinkButton1.UniqueID %>', ''); 
     //__doPostBack("LinkButton1","");
    
    }
    </script>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CausesValidation="false">LinkButton</asp:LinkButton>
                <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true"></asp:TextBox>
                <br />
                <br />
                <div onclick='FillText()'>
                    <asp:ImageButton ID="ImageButton1" runat="server" />
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
 
C#
 
 protected void LinkButton1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "Hello There";
        UpdatePanel1.Update();
    }

Open in new window

0
Comment
Question by:groovbox303
2 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 250 total points
ID: 21857108
Hi groovbox303,
You can trigger the same function in UpdatePanel without javascript.
eg:
  <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="ImageButton1" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CausesValidation="false">LinkButton</asp:LinkButton>
                <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true"></asp:TextBox>
                <br />
                <br />
                <asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" CausesValidation="false"/>
            </ContentTemplate>
        </asp:UpdatePanel>
 

private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        LinkButton1_Click(nothing,nothing);
    }

 protected void LinkButton1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "Hello There";
        UpdatePanel1.Update();
    }
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question