开发者

c# aspx modal window : how to redirect using javascript to same window (self)

开发者 https://www.devze.com 2023-01-12 22:43 出处:网络
I have been struggling with a problem that kept me busy for a few days now. I am programming c# .net web applications for an IE only environment and my current project contains a modal window. I hope

I have been struggling with a problem that kept me busy for a few days now. I am programming c# .net web applications for an IE only environment and my current project contains a modal window. I hope you guys can help me out here!

I have a couple of response.redirects in my modal page that work fine, with the addition of in the aspx file. But I also have a listview which is filled at runtime, where I add a onclick event to a tablecell using the attributes.add method which fires java script to do the redirect. The开发者_StackOverflow problem is this: The methods I used, location.href='x'; and window.open('x','_self'); sadly opens the link in a new window instead of in the same.

Would somebody know a way around this or how to solve this? I would be very grateful for any help.

protected void lvConditions_ItemDataBound(object sender, ListViewItemEventArgs e)
{
       ...

       label.Attributes.Add("OnClick", "window.open('Condition.aspx?action=selectedcondition', '_self');");

       ...
}

Thanks


use window.location instead of window.open()

 label.Attributes.Add("onclick", "window.location = 'Condition.aspx?action=selectedcondition';");


Try using window.location instead of window.open?


I knew there was a third way to do the redirect in js, but I forgot this one... Unfortunately this did not help either, the new page was still opened in a new window.

I changed the application now to work round the problem. Instead of selecting by clicking on the cell, I added an ImageButton for each line to do the select. Their links (PostBackUrl) I set in runtime and it works like a charm.

I will keep the old code as well though to see if someone can actually come up with the real solution for this.

Thanks Daniel and Dave for your reply. Anyone else who wants the have a throw at this?

0

精彩评论

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

关注公众号