开发者

How do I Activate a different Tab from inside a Page on a different tab and do a PostBack on it

I'm having trouble figuring out something that should be simple but I'm having trouble trying to figure it out.

I have a Page (Default.aspx) which contaiins a WebTab Control (Infragistics, but shouldn't matter really). Inside each Tab Control of the WebTab is another page, Page1.aspx, Page2.apx, so it's like this:

Default.aspx
WebTab
    WebTabControl(0)
        Page1.aspx <-- I'm in this codebehind after 
                   calling __doPostBack from JavaScript 
                   as I have a parameter from a WebDataGrid.
    WebTabControl(1)
        Page2.aspx <-- I want to open this page and pass it a parameter.

I'm in Page1.aspx codebehind doing a postback as I have a parameter that I need to pass to the next page, and I want to open Page2.apx which is inside the 2nd Tab.

Basically, I think I need to do 开发者_开发问答the following steps. 1. Set the Active Tab to WebTabControl(1) 2. Give it the Parameter that I have for it to do something with.

I know I'll have to shoot myself once someone tells how to do it :-) Thanks!


Ok AFAICU, WebTab control has WebTab and each webtab has page. Try this:

  1. Add auto postback feature of the control. So as to call the next tab and it will automatically load the aspx page.
  2. If you do not need Postback then do one thing, on the click event or tab change event of the tab control add some parameter in the query string. Like page.aspx?tab=1. Now on the page load event, use the logic below

          1. Check if Request[tab] is not null.
          2. use int.tryparse and get the tab number.
          3. Now on the basis of the load the tab and the page. 
             And make the tab active.
    


Thanks very much for the response, but that's not what I was looking for.

What I actually did to resolve this problem was to create a JavaScript function in the Default.aspx page that I was able to call from Page1.aspx.

This is the function in the Default.aspx Page, which activated the Tab that I needed and populated the search box with the value I needed from the WebDataGrid from Page1.aspx.

    <script type="text/javascript">
    function activateTab(rowId, tabId) {
        var tab = $find("WebTab1");
        var ctl;
        if (tabId == 3) {
            ctl = window.frames.document.frames[tabId].window.document.getElementById("WebDialogWindow2_tmpl_txtAddressNumber");
        }
        else if (tabId == 2)
            ctl = window.frames.document.frames[tabId].window.document.getElementById("WebDialogWindow2_tmpl_txtAccount");

        if (ctl != null) {            
            ctl.value = rowId;
            tab.set_selectedIndex(tabId, true, null);
            window.frames.document.frames[tabId].window.DoSearch(rowId);
        } 
    }
</script>

I was then able to call the activateTab() function from Page1.aspx with the following function, which is called from the DoubleClick event of the WebDataGrid (I needed to grab a value from the row that was selected.)

        function doubleClickRow() {
        var grid = $find("WebDataGrid1");
        //Get the ADDRESS_NUMBER value.
        var rowId = grid.get_behaviors().get_selection().get_selectedRows().getItem(0).get_cell(2).get_value();
        window.parent.activateTab(rowId, 3);
    }

The next step was to call this JavaScript function on Page2.aspx from the activateTab() function on Default.aspx as shown in the first code example.

        //Force a Postback
    function DoSearch(id) {
        HideSearch();
        __doPostBack("WebDataGrid1", id);
    }

This actually did the post back that I needed so that's all I had to do. If I wanted to pass those 2 __doPostBack() values into the Page2.aspx Page_Load event, I would have to do the following. However in my case the Post back was all I needed as I had already populated the search box.

            //Don't need these right now, but just in case we might I'll leave them in.
        string eventTarget = Page.Request.Params.Get("__EVENTTARGET");
        string eventArgument = Page.Request.Params.Get("__EVENTARGUMENT");
        Search();

For those who don't understand the last part with the __EVENT* code, it's possible if you use a ScriptManager, otherwise you have to code your own Parameters, which I won't get into here.

That's all there was to it. I certainly learned some JavaScript along the way here so I hope it's useful for someone else out there.

Thanks Dave

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜