?
Solved

Trigger client side java script from formview page index changed event within ajax update panel.

Posted on 2009-12-17
5
Medium Priority
?
795 Views
Last Modified: 2012-05-08
I have a .net fromview within an ajax update panel on my page which contains a hiddenfield called hfQuestionNo

as the user pages through the form the hidden field value increments.

The java script i want to run is:
Mediabox.open('url', 'title', 'width height');
this function opens a lightbox style window.

i need to run it when the hidden field value reaches a value that is specified in either the server side or client side scipt.

I am not really sure where to start.

Many Thanks
0
Comment
Question by:Ross-C
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
five22bags earned 2000 total points
ID: 26071654
Here is my sample project code for you. It calls a javascript alert when the value of the hiddenfield reaches 3:

in your aspx:
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <br />
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        </ContentTemplate>
        
    </asp:UpdatePanel>
 
 
 
in the codebehind (.cs):
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            HiddenField1.Value = "0";
    }

    
    protected void  Button1_Click(object sender, EventArgs e)
    {
        int val = int.Parse(HiddenField1.Value);
        val++;
        HiddenField1.Value = val.ToString();

        if (val == 3)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "hi", "alert('hi!')", true);
        }
    }

Open in new window

0
 
LVL 11

Author Comment

by:Ross-C
ID: 26071785
thanks thats great, i cannot use the page load event though because the form view is in an update panel.  Would like to keep it in the update panel if possible.
0
 
LVL 11

Expert Comment

by:five22bags
ID: 26071820
You don't need the page load. I was just setting up the initial value of the HiddenField. It was just an example.
0
 
LVL 11

Author Comment

by:Ross-C
ID: 26071883
sorry, i wrongly assumed you'd misunderstood my question.  I will give it a go thanks
0
 
LVL 11

Author Closing Comment

by:Ross-C
ID: 31667258
many thanks, just the job
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 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