Solved

AJAX CollaspiblePanel + Javascript alert

Posted on 2008-10-14
5
370 Views
Last Modified: 2012-06-21
Hi all,

I have a page with a ajax CollaspiblePanel and a postback button. Click on the button will initiate a javascript alert box. I found that if the panel is closed, the panel will be expanded for a second while the javascript alertbox appear on button click. But it will stay close if the javascript alert is removed from script.

Can I ask if there is any work around if I want to keep the javascript alertbox together with the CollaspiblePanel? Thanks.
0
Comment
Question by:esther_6694
  • 2
5 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 22718326
Place a literal control at the end of the form.

just inside the end of form tag

i.e

<asp:Literal id=".............>
</form>

Instead of writing Response.Write("code for alert..........

Write

Lit1.text = "<script language='javascript'>alert('hi');</script>";

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22718690
You can set the OnClientClick event and set the javascript function that you want to perform for that button. This OnClientClick happens on client side (browser).
Or dynamically from server:

for example in your Page_Load:
mybutton.Attribute.Add("onClick", "alert('hi world');");
//this attribute is for rendering only.

Hope this helps

JINN
0
 

Author Comment

by:esther_6694
ID: 22727303
My button call javasciprt via RegisterStartupScript:
msgScript = "alert('hahaha'); "
ScriptManager.RegisterStartupScript(requester, requester.GetType(), "myscript", msgScript, True)


0
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 250 total points
ID: 22728698
ohh,

That way, it's startup script, and only initialized once on your post back. I think what you need is register for a function block, so everytime you click on expand (for example) that script block will be executed or acts the way you want it.

Hope this helps

JINN



 public void Page_Load(Object sender, EventArgs e)

  {

    // Define the name and type of the client scripts on the page.

    String csname = "ButtonClickScript";

    Type cstype = this.GetType();    

    ClientScriptManager cs = Page.ClientScript;

    

    // Check to see if the client script is already registered.

    if (!cs.IsClientScriptBlockRegistered(cstype, csname))

    {

      StringBuilder cstext2 = new StringBuilder();

      cstext.Append("<script type=\"text/javascript\"> function DoClick() {");

      cstext.Append("Form1.Message.value='Text from client script.'} </");

      cstext.Append("script>");

      cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), false);

    }
 

     mybutton.Attribute.Add("onClick", "DoClick();");

  }

Open in new window

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

Suggested Solutions

Title # Comments Views Activity
SSL https .net web site force redirect 3 31
What .NET URL re-routing tool did I use? 2 31
C# Single Form 8 26
How can I echo a PHP variable in AJAX function? 7 25
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

943 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

5 Experts available now in Live!

Get 1:1 Help Now