sr28
sr28

Reputation: 5106

Greybox GB_showcenter not displaying popup

I'm using the GreyBox js library to display a popup. To give some more general context I've rewritten a solution that was in VB.NET to C#. The code is essentially identical in both, just with the differing syntax used in both. However, the following works in the VB.NET solution but not the C# version:

VB

script = String.Format("GB_showCenter('My Caption', '../MyPage.aspx?number={0}&state={1}&ID={2}',300,600 );", num, MyLabel.Text, Label_id.Text)

ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType(), Guid.NewGuid().ToString(), script, True)

This works and when a button is clicked it navigates the user to a new page that has the size restricted. However, the following doesn't work.

C#

script = String.Format("GB_showCenter('MyCaption', '../MyPage.aspx?number={0}&state={1}&ID={2}',300,600 );", num, MyLabel.Text, Label_id.Text);

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), script, true);

What should happen is when I click a link button the text in the MyLabel is evaluated and if the text is the correct one then the string 'script' is set appropriately and registered with the scriptmanager. Running through with the VS2010 debugger this is all happening as expected. However, the user isn't navigated to a new page called 'MyPage.aspx'. The url stays the same and the page goes blank.

What's more interesting is that if I click the scroll bar the current page is briefly displayed along with the new popup shown above it on the same page. So my current theory is that it's something to do with how the javascript is called from the c#. Any ideas?

UPDATE

I went through with the vs2010 debugger and decided to see if MyPage.aspx was hit at all. It wasn't, as I expected. However, I then thought that perhaps it wasn't firing it's Page_Load event. So I added in:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    Load += Page_Load;
}

I set a breakpoint on the Page_Load event of MyPage.aspx and this was now being hit. All the logic was being run through correctly, but I was still getting the same issue (blank page etc, url not changing to MyPage.aspx etc).

Upvotes: 2

Views: 851

Answers (1)

sr28
sr28

Reputation: 5106

I found the answer, though it's not really related to GreyBox specifically. I'd incorrectly made something a script when it should have been a link and added incorrect attributes. The type was text/javascript when it should've been text/css. This seemed to make the difference. To give more context I had the following:

 HtmlGenericControl Link5 = new HtmlGenericControl();
 Link5.TagName = "script";
 Link5.Attributes.Add("href", ResolveClientUrl("~/MyApp/Greybox/gb_styles.css"));
 Link5.Attributes.Add("rel", "stylesheet");
 Link5.Attributes.Add("type", "text/javascript");
 Page.Header.Controls.Add(Link5);

The 'TagName' should've been 'link' and the Link5.Attributes.Add("type", "text/javascript") should've been 'text/css'.

Upvotes: 1

Related Questions