Link to home
Start Free TrialLog in
Avatar of digitalZo
digitalZoFlag for India

asked on

Custom Page Class

A solution was given here:
https://www.experts-exchange.com/questions/23482039/iframe-and-parent-page-refresh.html
<<<<<<<<<
Ok in that case you could create a custom page class  derived from System.Web.UI.Page and write the above code in that file . In those 10 pages where you need this functionality , dervie them from this custom page class . How ever note that we are refering to elements from the client side as  parent.document.getElementById('DropDownList1'). etc . So the expectation is that you have a drop down named 'DropDownList1' in all those 10 pages .
>>>>>>>>>

Can anyone show me how to do this?
ASKER CERTIFIED SOLUTION
Avatar of codeclay
codeclay
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
Which ever page needs that script , just inherit it from that custom page class like in the below snippet .

public partial class ClientSideOptionAdd :QPage

The code below is the codebehind of the aspx page where the client side add happens .
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class ClientSideOptionAdd :QPage 
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            string strClientAddedValues = HiddenField1.Value;
            if (strClientAddedValues.Trim() != String.Empty)
            {
                string[] str = strClientAddedValues.Split(new char[] { ',' });
                DropDownList1.Items.Add(new ListItem(str[0], str[1]));
                HiddenField1.Value = String.Empty;
            }
        }
    }
}

Open in new window

Avatar of digitalZo

ASKER

Thanks for your help but unfortunately that didn't work.

#1 On page load itself, it submits and gives the error "state" is null or void.

#2 it's giving the same problem as in the previous thread. that is when the value adds in the dropdown but when i do an autopostback from a different dropdown, the value disappears and i've to click refresh.
sorry gives the error: state" is null or not an object.