Could the MenuItemClick events happens before Page_Load events? Thanks a lot!

angel_lee 2006-08-25 12:01:18
I have a menu on the top of page.
I set ViewState["dataTable"]=null; in MenuItemClick events.

My Page_Load events include some codes like this:

if (ViewState["dataTable"] != null)
{
dataTable = (DataTable)ViewState["dataTable"];
}
else
{
dataTable = null;
}

DataBind();

My expected action: Don't show GridView after click a new item of menu.

The actually result: It still show GridView after the first times click the new item of menu, the GridView don't show again after the second times click the new item in menu.

I track the code, menuItemClick events happens after Page_Load events, that's the reason.

How could I get my expected action and result?

Thanks a lot!
...全文
447 38 打赏 收藏 转发到动态 举报
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
Knight94 2006-08-31
  • 打赏
  • 举报
回复
I guess you have misunderstood "_parent" means.

If your current page is made up of framesets, and you can set target with "_parent" value which can render contents of a link in one of frame to replace current page.

So the condition that "_parent" works is that your page is made up of framesets.

pls check it first.
angel_lee 2006-08-31
  • 打赏
  • 举报
回复
Nope, I want to use parent.

I have a asp home page, click one of the button in this page open my current .net .aspx page. My .net page may return many results after search in current page. If I click the results that come from dataSet.Table[0]. It will open a new page.

If I click the other results that come from dataSet.Table[1]. It will return the page in the original asp page, not my current .net page.
Knight94 2006-08-31
  • 打赏
  • 举报
回复
"_parent": Renders the content in the immediate frameset parent;
"_top": Renders the content in the full window without frames;

I guess you should change "_parent" with "_top".
pls check your scenario and choose a correct one.
angel_lee 2006-08-31
  • 打赏
  • 举报
回复
Thanks a lot, Knight94(愚翁)

The way you taught me works 70%. :)

Please take a look at my method.

protected string getTargetString(string rstUrl)
{
string targetStr = "_parent";
if (rstUrl.Substring(14, 18) == "repositoryFile.asp")
{
targetStr = "_new";
}
return targetStr;
}


Presently, it works to open my page in a new window. But I could not open the other pages in parent window, since my current window is .net codes, and my parent window is asp codes.

I think maybe i need to add something else besides the Target property. What should I do?

Thanks!!!
angel_lee 2006-08-31
  • 打赏
  • 举报
回复
My current .net page do not have framesets.

I've found a method to solve target="_parent". The code was correct, but it did not works. I gave my parent window a name "aaa" , then target="aaa" in current page. It works this time. :)

Thanks a lot, Knight94(愚翁)!!!
Knight94 2006-08-30
  • 打赏
  • 举报
回复
to But for "resultName" column, I want to have different options while click different links result in the same column.(Usually i have throusands of records show on screen.)

you can set target property as text property as follows:
Target="<%# GetTargetString(Eval("resultUrl").ToString()) %>"

//in server side
public string GetTargetString( string URLString )
{
// you can return target string according to url here
// such as "_new", "_self" etc.
}
angel_lee 2006-08-30
  • 打赏
  • 举报
回复
Thanks a lot, Knight94(愚翁)

I think that I did not make sense.

It will open a new window for all the "resultName" links if I set "target" property, right?

But for "resultName" column, I want to have different options while click different links result in the same column.(Usually i have throusands of records show on screen.)

For some records, which come from dataSet.Table[0], I want to open a new window when click the "resultName" links.

For the other records, which come from dataSet.Table[1], I would like to open the result in parents window (my current window opens when click the parents window, they are two windows) when click the "resultName" links.

I think maybe we may do something in getSearchTable method.

But I don't know how to change this part?

dr[2] = "..\\..\\English\\repositoryFile.asp?repositoryID=" + rDR[2].ToString().Trim();



Knight94 2006-08-30
  • 打赏
  • 举报
回复
Set "target" property as follows:
<ItemTemplate>
<asp:HyperLink ID="hyperLinkResult" runat="server" Text='<%# getSubString(Eval("resultName").ToString()) %>' NavigateUrl='<%# String.Format(Eval("resultUrl").ToString(), Eval("resultName"))%>'
Target="_new" />
<br>
<asp:Literal ID="literalResult" runat="server" Text='<%# getSubString(Eval("resultDescription").ToString()) %>' />
<br> <br />
</ItemTemplate>
angel_lee 2006-08-30
  • 打赏
  • 举报
回复
Here has another question. Please take a look at the following codes.


protected DataTable getSearchTable(DataSet dataSet, String srhArea)
{

tableRst = new DataTable();
tableRst.Columns.Add("resultName", typeof(string));
tableRst.Columns.Add("resultDescription", typeof(string));
tableRst.Columns.Add("resultUrl", typeof(string));

if (srhArea.ToUpper() == "DOCUMENT")
{
if (dataSet.Tables[0].Rows.Count > 0)
{
foreach (DataRow rDR in dataSet.Tables[0].Rows)
{
DataRow dr = tableRst.NewRow();
dr[0] = rDR[0];
dr[1] = rDR[1];
dr[2] = "..\\..\\English\\repositoryFile.asp?repositoryID=" + rDR[2].ToString().Trim();
tableRst.Rows.Add(dr);
}
}

if (dataSet.Tables[1].Rows.Count > 0)
{
foreach (DataRow rDRF in dataSet.Tables[1].Rows)
{
DataRow dr = tableRst.NewRow();
dr[0] = rDRF[0];
dr[1] = System.String.Empty;
dr[2] = "lralDocumentRepositoryExplorer.aspx?folderID=" + rDRF[1].ToString().Trim();
tableRst.Rows.Add(dr);
}
}

return tableRst;
}
}

This two columns was bound into GridView as follow.

<ItemTemplate>
<asp:HyperLink ID="hyperLinkResult" runat="server" Text='<%# getSubString(Eval("resultName").ToString()) %>' NavigateUrl='<%# String.Format(Eval("resultUrl").ToString(), Eval("resultName"))%>' />
<br>
<asp:Literal ID="literalResult" runat="server" Text='<%# getSubString(Eval("resultDescription").ToString()) %>' />
<br> <br />
</ItemTemplate>

Question:
It opens the new page in current window (do not open new window) when i click the "resultName" link in GridView.
I want to open a new window when click the "resultName" links in dataSet.Table[0] .
I would like to open the new page in parents window of current window (not current window) when click the "resultName" links in dataSet.Table[0].

So how should i coding?


angel_lee 2006-08-30
  • 打赏
  • 举报
回复
It's really weird, anyway thanks a lot, Knight94(愚翁)

Knight94 2006-08-30
  • 打赏
  • 举报
回复
It looks very weird. I can't create the context same as yours to get what problem you have got.

Sorry!

Hope others can help you.
angel_lee 2006-08-29
  • 打赏
  • 举报
回复
hi Knight94(愚翁),

Thanks so much for your focus and help.

Althrough your words "you should not bind gridview here, because you do it in pageindexchanging event." looks reasonable. But my paging do not work any more after I got rid of the IsPostBack codes. It works well if I have this part of codes.

This paragraph of nonsense is useful in fact. :)
fengyeng 2006-08-29
  • 打赏
  • 举报
回复
mark
Knight94 2006-08-29
  • 打赏
  • 举报
回复
Sorry!
change
you should bind gridview here, because you do it in pageindexchanging event.

with
you should not bind gridview here, because you do it in pageindexchanging event.
Knight94 2006-08-29
  • 打赏
  • 举报
回复
to Is any other wrongs with my codes?

In your page-load event, there are some codes which is handled with the property named "IsPostback" true value.
they are follows:

if (ViewState["tableResult"] != null)
{
tableResult = (DataTable)ViewState["tableResult"];
}
else
{
tableResult = null;
}
srhResultGridView.DataSource = tableResult;
srhResultGridView.DataBind();

you should bind gridview here, because you do it in pageindexchanging event.
angel_lee 2006-08-28
  • 打赏
  • 举报
回复
What's the difference between PageIndexChanging and PageIndexChanged?

I knew PageIndexChanging happen before GridView control handle, PageIndexChanged happen after GridView control handle.

Could i use the same codes in PageIndexChanged as PageIndexChanging?

It has an errors after i put my paging codes in PageIndexChanged.

Error 8 'System.EventArgs' does not contain a definition for 'NewPageIndex' C:\Inetpub\wwwroot\LRAL32UPDATE2\src\viewcontroller\lralSearchToolBar.aspx

Do i need to write some specific codes for PageIndexChanged void?

protected void srhResultGridView_PageIndexChanged(object sender, EventArgs e)
{
if (ViewState["tableResult"] != null)
{
tableRst = (DataTable)ViewState["tableResult"];
}
srhResultGridView.DataSource = tableResult;
srhResultGridView.PageIndex = e.NewPageIndex;
srhResultGridView.DataBind();
}
angel_lee 2006-08-28
  • 打赏
  • 举报
回复
I wrote my pageIndexChanging as yours. All the other pages work well, but the issue is still there. The same result as my PageIndexChanging.

Is any other wrongs with my codes?
Knight94 2006-08-28
  • 打赏
  • 举报
回复
Sorry!
I gave you some wrong info.

In page handle, use "PageIndexChanging" event
I do some test as follows,
//in page-load event
protected void Page_Load(object sender, EventArgs e)
{
if (!(this.IsPostBack))
{
DataTable dtTest = new DataTable("Test");
dtTest.Columns.Add("Name", typeof(string));
dtTest.Columns.Add("Address", typeof(string));
for (int i = 0; i < 22; i++)
dtTest.Rows.Add(new object[] { "Name"+i.ToString(), "Address"+i.ToString() });

dtTest.AcceptChanges();

ViewState["tableResult"] = dtTest;
grdTest.DataSource = dtTest;
grdTest.DataBind();

}
}

// in pageindexchanging event
protected void grdTest_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (ViewState["tableResult"] == null) return;
DataTable dtTest = ViewState["tableResult"] as DataTable;
if (dtTest != null)
{
grdTest.DataSource = dtTest;
grdTest.PageIndex = e.NewPageIndex;
grdTest.DataBind();
}

}

It works fine. So you check what is difference between yours and mine.
Knight94 2006-08-27
  • 打赏
  • 举报
回复
change grid's "PageIndexChanging" event with "PageIndexChanged" event
angel_lee 2006-08-27
  • 打赏
  • 举报
回复
private void searchBtn_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ViewState["tableResult"] = "";
srhResultGridView.Visible = true;
try
{
if (Menu1.SelectedItem.Text == "Document")
{
srhArea = "document";
}
else if (Menu1.SelectedItem.Text == "Knowledge Exchange")
{
srhArea = "forums";
}
else if (Menu1.SelectedItem.Text == "Learning Modules")
{
srhArea = "learning";
}
else if (Menu1.SelectedItem.Text == "All")
{
srhArea = "all";
}
LRALWebService.lralWSSearch srhResult = new LRALWebService.lralWSSearch();
srhKeyWords = keyWordsTB.Text.ToString();
srhType = srhTypeDDL.SelectedItem.Value;
if (srhKeyWords == System.String.Empty)
{
ViewState["tableResult"] = null;
messageTB.Text = "Please input the key words that you want to search!";
srhResultGridView.Visible = false;
return;
}
ds = srhResult.lralSearch(srhKeyWords, srhType, srhArea, LRAL_UID, true);
if (ds.Equals(null))
{
ViewState["tableResult"] = null;
messageTB.Text = "Please input the valid key words!";
srhResultGridView.Visible = false;
return;
}
else
{
int tableNum = 0;
for (int i = 0; i < ds.Tables.Count; i++)
{
if (ds.Tables[i].Rows.Count < 1)
{
tableNum++;
}
}
if (tableNum == ds.Tables.Count)
{
ViewState["tableResult"] = null;
messageTB.Text = "The key words you are searching is not exist!";
srhResultGridView.Visible = false;
return;
}
else
{
messageTB.Text = "";
}
}

tableResult = getSearchTable(ds, srhArea);
ViewState["tableResult"] = tableResult;

srhResultGridView.DataSource = tableResult;
srhResultGridView.DataBind();
}
catch (Exception exc)
{
// int page = srhResultGridView.PageIndex;
// page = -1;
// page = page >= 0 ? page : 0;
messageTB.Text = "Unexpected exception:" + exc.ToString();
}
}

protected void srhResultGridView_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
if (ViewState["tableResult"] != null)
{
tableRst = (DataTable)ViewState["tableResult"];
}
srhResultGridView.DataSource = tableResult;
srhResultGridView.PageIndex = e.NewPageIndex;
srhResultGridView.DataBind();
}

protected string getSubString(string rstDescription)
{
if (rstDescription.Length > 200)
{
rstDescription = rstDescription.Substring(0, 200) + "...";
}
return rstDescription;
}
加载更多回复(18)

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧