开发者

Eval() in ASP. How to pass values on redirect throught session

I have this image button inside a grid view which redirects the groupname to the send message.aspx.

 <asp:ImageButton ID="img_Send" ImageUrl="Styles/Images/Message.jpg" Enabled="True" Width="" runat="server" PostBackUrl='<%# Eval("GroupName", "SendMessage.aspx?GroupName={0}") %>'></asp:ImageButton>

http://localhost:48996/SurelyK/SendMessage.aspx?GroupName=Jobs this is the url

Is it possible to store the value in a session in the client side so that i can use it in server side coding.

i dont want to pass the value in the URL. How can i do it without passing it in URL.

2nd q: I am also doing the same in user page where I pass the user id.

http://localhost:48996/SurelyK/SendMessage.aspx?UserID=3

In my sendmessage server side code i have to save the 开发者_如何学Pythonmessage in the message table and then save the username and the message id in usermessage table.

the code for inserting in userdetails usermessage table and code for inserting groupdetails in grouptable is different. I have to do both in send button click. How to check which page redirected to send message page, is it group or user page..


You can use following scenario. But for that you need to use Server.Transfer instead of Respons.Redirect

http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage.aspx


What you are looking for is a cookie. Cookies store client side state information and are sent with every request to the server. Here is an article on how to use them in ASP.NET

http://www.codeproject.com/KB/aspnet/Beginners_Cookies.aspx


One possibility is to do what you say, i.e. put the value in Session in one page and retrieve it in another page. For example:

In one page you do this:

Session["Key"]=value;

And in the other page you retrieve it like this:

var myData = Session["Key"];

You can also do what JohnFX proposes, which is create a cookie on Page A and read it on Page B.

For your second question, if you go with the Session approach, you could do this:

On the page that redirects the user to the SendMessage page you can either do this:

Session["USER"]="User" or Session["GROUP"]="Group";

On the SendMessage.aspx page, you check if Session["User"] is not null and if it isn't, that means that the user was redirected from the User page; If it is null, then you check if Session["Group"] is not null, if it isn't that means the user was redirected from the Group page.


Put the groupname in a hidden html field updated by the client. It will get posted to the server where you can read it from the request.

<asp:HiddenField runat="server" ID="groupname" Value='<%# Eval("GroupName") %>'/>
<asp:ImageButton ... PostBackUrl="SendMessage.aspx" />

Then in SendMessage:

var groupname = Request["GroupName"]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜