c*o 发帖数: 70 | 1 Once a button is clicked on a web form, a Post message will send to the
server, where the code Page_Load () will be executed. However, I don't want to
initialize the Profile p again, so I put it is !IsPostBack(). But in this
case, the p will be null in the button's click event handling function
lkbtEmail_Click(). If I put initProfile() out of !IsPostBack(). It works. But
the initProfile() is a procedure which get a lot of information from the
database. I just want to do it once. How can I do it? |
|
p*p 发帖数: 75 | 2 看到几个有趣的问题,如果不看ASP.NET source code, 几乎就无法解决。
private void Page_Load(object sender, System.EventArgs e)
{
DropDownList ddlDynamic = new DropDownList();
ddlDynamic.ID = "ddlDynamic";
HtmlForm form1 = (HtmlForm)this.FindControl("Form1");
if (!IsPostBack)
{
ddlDynamic.Items.Add("Before");
}
form1.Controls.Add(ddlDynamic);
if (!IsPostBack)
{
ddlDynamic.Items.Add("After");
}
}
在Page上扔个Button, |
|
s******e 发帖数: 114 | 3 redirect pagaA to pageB
if pageA is really simple, then pagaA can be a html file. you simply modify
action attribute of form tag in pagaA.html to point to pagaB.aspx
if PagaA is really simple, then pagaA and pageB can be same, say pagaAB.aspx
, pagaA will be rendered in ispostback!=true block of PageAB.aspx.
if PagaA is not so simple(ie involve some postback processing), then In
pagaA.aspx, you can use server.transer to redirect to pagaB.aspx.
if PagaA is not so simple(ie involve some postback |
|
m*****h 发帖数: 18 | 4 not working
here is what i have
protected void Page_Load(object sender, EventArgs e)
{
cmdSave.Attributes.Add("onClick", "save();");
if (!IsPostBack)
{
clsContent c = new clsContent(ContID);
divcont.InnerHtml = c.Content;
}
}
function save()
{
var div1 = document.getElementById('<%=divcont.ClientID %>').innerHTML;
var hid1 = document.getElem |
|
k****i 发帖数: 1072 | 5 R u sure?
data binding in pageload will overwrite the value retrieve from viewstate and
would cause the problem that julyan encountered.Unless you use !IsPostBack |
|
G**T 发帖数: 388 | 6
and
ur right, use NOT isPostBack
line |
|
p*p 发帖数: 75 | 7 另外一个例子,动态创建DataGrid。 同样,随便扔个button可以postback. 运行正常.
private class Employee
{
string id;
string name;
public string Id
{
get { return id; }
}
public string Name
{
get { return name; }
}
public Employee(string id, string name)
{
this.id = id;
this.name = name;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid grid = new DataGrid() ;
HtmlForm form1 = (HtmlForm)this.FindControl("Form1");
form1.Controls .Add(grid);
if (!IsPostBack)
{
Employee[] people = new Employee[] { new Emp |
|
k****i 发帖数: 1072 | 8
DataGrid grid = new DataGrid() ;
grid.AutoGenerateColumns = false;
BoundColumn column = new BoundColumn() ;
column.HeaderText = "Name";
column.DataField = "Name";
grid.Columns.Add(column);
HtmlForm form1 = (HtmlForm)this.FindControl("Form1");
form1.Controls .Add(grid);
if (!IsPostBack)
{
Employee[] people = new Employee[] { new Employee("1", "Steve") , new
Employee("2", "John") , } ;
grid.DataSource = people;
grid.DataBind() ;
} |
|
p*p 发帖数: 75 | 9 "on PostBack, the DataGrid1.DataSource is null"
Yes, it's right. This is the basic concept must bear in mind. in ASP.NET, the
Control does not hold the Data. Although DataGrid, Repeater are called
Data-Bound controls, the Control can access to the data only when the
DataBind() is called:
if (!IsPostBack)
{
datagrid.DataSource = data;
datagrid.DataBind(); // datagrid use DataSource
to populate the controls
}
when posted back, the datagrid has no i |
|
f*****e 发帖数: 5177 | 10 if (!this.IsPostBack)
{
load your crystal report
}
rep
道会
效率 |
|
y********o 发帖数: 2565 | 11 I think my implementation of the counters are correct.
protected void Page_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack)) // If page is loaded the 1st time.
{
// Create two counters with initial values 0
// in the Session.
Session["counter"] = 0;
Session["innerCounter"] = 0;
}
else // Otherwise.
{
// Retrieve counter value from Session.
int outerCounter = (int)S |
|
c*********e 发帖数: 16335 | 12 小米加步枪写jsp的人飘过~~~
servlet,beans,get/setAttribue,get/setParameter,action=xxx.jsp,dispatch到xxx.
jsp,request.xxxx,hibernate,有些地方竟然还要写<% %>, sigh. 一个jsp文件,跳到
下一个jsp文件,跳到servlet,又是传值什么的。
貌似jsp没有asp.net的那种 !isPostBack, 不能forward给自己这个网页,比如要把搜
索数据库的结果列表到当前网页,没有asp.net那么方便。 |
|