Solved

__doPostBack Not Working

Posted on 2008-06-18
2
2,108 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now