Link to home
Start Free TrialLog in
Avatar of Sirdots
Sirdots

asked on

How to control width and height of an aspx page from code behind

I have a page that uses they hyperlink control. I want to be able to navigate to a popup window
with specific dimensions and pass a parameter at the same time to the AttorneyContact page.

I have my html like this :
<asp:HyperLink ID="HyperLink1" NavigateUrl="~/AttorneyContact.aspx" Target="blank" runat="server" >Attorney contact information |</asp:HyperLink>

<Fields>
            <asp:BoundField DataField="CaseNumber" HeaderText="CaseNumber" ReadOnly="True"
                SortExpression="CaseNumber" />

</Fields>


Because I need to use the value of a detailsview as my parameter, I had to pass this from the onload event of my page.

this.HyperLink1.NavigateUrl = "AttorneyContact.aspx?" + this.DetailsView1.Rows[0].Cells[1].Text;

How can i set the width and height of this page and turn off unnecessary toolbar from the line above within my code behind.
Avatar of Wikkard
Wikkard
Flag of Australia image

You will need to inject client side script to control the client browse from your code behind.

Something like:
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "setsize", @"
function setWindowSize(){
//whatever cross browser javascript you like to change window size.
window.height=100;
window.width=100;
  }  
", true);
Avatar of Sirdots
Sirdots

ASKER

how do i now apply your code above to this line??

this.HyperLink1.NavigateUrl = "AttorneyContact.aspx?" + this.DetailsView1.Rows[0].Cells[1].Text;
You dont.

You apply the code to the attorneycontact.aspx page - to make it resize itself when loaded.

So in the page_load event of attorneycontact.aspx put the code I posted above.
Unfortunately ths solution CB posted isnt really applicable as it only talks about calling javascript on the SAME page that contains the hyperlink/linkbutton.
You need to cause some javascript to run AFTER the attorneycontact.aspx page loads to resize it, you cant do it before the page loads because it doesnt exists at that time.

SOLUTION
Avatar of CB_Thirumalai
CB_Thirumalai
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sirdots

ASKER

One will expect that the hyperlink below will work since i have the
navigateurl part in the code behind of my page_load.
This does not work.

singlerecord.aspx
------------------------

<div id="navcontainer">    
    <asp:HyperLink ID="HyperLink1"  runat="server" >Attorney contact information |</asp:HyperLink>    
</div>


singlerecord.aspx code behind
-------------------------------
if i do this below then it works with the javascript but the toolbar is still there

<div id="navcontainer">    
    <asp:HyperLink ID="HyperLink1"  NavigateUrl="~AttorneyContact.aspx" Target=_blank runat="server" >Attorney contact information |</asp:HyperLink>    
</div>


singlerecord.aspx
-------------------
protected void Page_Load(object sender, EventArgs e)
    {
       
        this.HyperLink1.NavigateUrl = "javascript:popup(600,700,'AttorneyContact.aspx?" + this.DetailsView1.Rows[0].Cells[1].Text + "');";
         
    }

The sizing does not work at all.


Attorneycontact.aspx   -- html section
---------------------

<head runat="server">
    <title>Untitled Page</title>
  <script type="text/javascript>
function popup(width, height, url)
    {
        var win = window.open(url,'popup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height);
    }
</script>

</head>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial