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

AJAX CollaspiblePanel + Javascript alert

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
esther_6694
Asked:
esther_6694
  • 2
1 Solution
 
informaniacCommented:
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
 
jinn_hnnlCommented:
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
 
esther_6694Author Commented:
My button call javasciprt via RegisterStartupScript:
msgScript = "alert('hahaha'); "
ScriptManager.RegisterStartupScript(requester, requester.GetType(), "myscript", msgScript, True)


0
 
jinn_hnnlCommented:
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now