PDA

Click to See Complete Forum and Search --> : UserControl


Sansari71
Jan 27th, 2005, 03:50 PM
I have a user control which is linked to the db. It has three buttons: Save, Cancel and Refresh. I wanted to pop up a showmodal window if the user clicks cancel or refresh. I am using C# and javascript. I have added the javascript code for the buttons onclick events. It is not working:
The showmodal call is like this
window.showModalDialog(webpage,,pagesettings);
can someone tell me what I am doing wrong? Thanks in advance

mendhak
Jan 27th, 2005, 11:18 PM
What are the values of webpage and pagesettings? Try hardcoding all the values and then working your way towards vars from there.

Sansari71
Jan 28th, 2005, 08:22 AM
webpage is the asp page for the modal window and pagesetting is where the popup window should be and what should be its width, height

Magiaus
Jan 28th, 2005, 09:17 AM
Is that IE only or does Netscape and so on support the DialogBox type window?

Sansari71
Jan 28th, 2005, 10:05 AM
It's IE Only.

Sansari71
Jan 28th, 2005, 10:09 AM
Let me rephrase the question. Can I call onclick event of a button on a aspx page from the usercontrol. Both usercontrol and button is on the same aspx page. Thanks

Magiaus
Jan 28th, 2005, 10:16 AM
To the best of my knowledge there is no easy way. I had this problem with my cancel button. What I finally did which sucked was to check the URL of the page and take a special action based on the page name. I did things like adding popup to the name of pages that where used in popups and having a special cancel for popups and so on.

The other answer is to expose the event as an event of the user control and attach an event at the page level. This sucks too because well the point of user controls is ready to go drop in elements....

What I do to show a popup from a button is to reg a startup script for the page.

Sansari71
Jan 28th, 2005, 10:34 AM
Can you show me through code of what you mean?
I guess I am finding out is that you can't use document.getElementById in a user control because it has no idea. Thanks again

Magiaus
Jan 28th, 2005, 10:41 AM
The UserControl doesn't have a .ClientID but the controls in the user control do.

This is from a Cancel Button in one of my UserControls. If the Control is in a PopUp it closes the PopUp otherwise it redirects to another page.

private void Button2_Click(object sender, System.EventArgs e)
{
if(Request.Url.AbsoluteUri.ToLower().IndexOf("popup") != -1)
{
Page.RegisterStartupScript("-closeMe" + this.UniqueID,"<script language=\"JavaScript\"><!--\r\nwindow.close();\r\n\\\\--></script>");
}
else
{
this.ViewState.Clear();
Response.Redirect(this.Page.Request.Url.AbsolutePath, true);
}
}
In this case I redirect back to the root page because I load My controls on the fly unless they are in a Popup. The default control for most of my pages is a UserControl with a DataGrid used to view the info.