开发者

Sharepoint Webpart posting data to Application Page via PostBackUrl

I have a Webpart that contains a couple of dropdowns on an update panel. There is a submit button that has the PostBackUrl set to a sharepoint Application Page

<asp:DropDownList ID="ClassSelector" runat="server" Enabled="False" 
    AutoPostBack="True" onselectedindexchanged="ClassSelector_SelectedIndexChanged">
    <asp:ListItem Selected="True" Value="-null-">Select Class...</asp:ListItem>
    <asp:ListItem Value="1">Class 1</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="开发者_运维知识库btnSubmit" runat="server" Text="Show Page" Enabled="False" 
                PostBackUrl="~/_layouts/MyWebParts/MyAppPage.aspx" />

This works in redirecting the browser to the Application Page I have created, but I am having trouble accessing the form data.

On the Page_Load function of the Application Page I have the following debugging code.

protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text = "";

    foreach (String s in Page.Request.Form.AllKeys)
    {
        Label1.Text += s + ": " + Page.Request.Form[s] + "<br />";
    }

}

This shows that the data I need has in fact been posted to the page.

ctl00$m$g_24a73cf8_8190_4ddb_b38b_bf523b12dbd3$ctl00$SemesterSelector: 28
ctl00$m$g_24a73cf8_8190_4ddb_b38b_bf523b12dbd3$ctl00$ClassSelector: 11-0021-A

But when I try to access this as:

Page.Request.Form["ClassSelector"]

Nothing is returned. I know I must be missing something simple here, but I am not sure what.

Any help is greatly appreciated.


Ah, the ASP.NET master page prefix problem! One of my favorites.

The master page for your application page puts a prefix in front of your server-side controls so that they will be unique. If you end up access your control via the Form collection, you have to access it using not only the control ID, but also the ContentPlaceholder prefix. That's why you see such a large ID dumped out of your debugging logic.

If you want to programmatically get to the ID of the control, you can use FindControl, but you'll have to target the apppropriate content placeholder scope for this. Here's a good tutorial/explanation here (which really emphasizes how complex this can get!).

Of course, the other option you can use is just hard-coding the control id based on what you're seeing from your debugging code...but that won't be reliable if you change content placeholders or more your control to a different container.

I guess the answer depends on how static your controls will be.

Hope this helps. Good luck!!


Well to access it that way you would have to use

Page.Request.Form["ctl00$m$g_24a73cf8_8190_4ddb_b38b_bf523b12dbd3$ctl00$ClassSelector"]

As you can actually see from your code where you set the label text to s plus Request.Form[s]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜