如何以编程方式触发ASP.net页面中的事件

时间:2011-07-19 15:39:51

标签: c# asp.net

我有一组动态构建的页面,包含Data(TextBoxes,DropDowns等)控件和两个导航按钮(Previous和Next)。

如果我点击“下一步”按钮,表单会验证所有数据,如果有效,则转换到下一页。

我想调用其中一个页面并触发下一个按钮,使用HTTP Post提交所有数据(http://en.csharp-online.net/HTTP_Post)。

在结束时我想获得下一页的Html。

我似乎无法使用下面的代码触发“下一个按钮”。

string url = "http://localhost/Forms/Default.aspx?FormId=b5949b04-95bc-4275-a595-8e622174fd68";
string viewstate = "/wEPDwULLTExNzY4NjMwMTgPZBYCZg9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YRYCAgMPZBYCAgEPZBYCAgEPZBYGAgEPZBYCAgEPFgIeBFRleHQFcjx1bCBjbGFzcz0nYnJlYWRjcnVtYic+PGxpIGNsYXNzPSdDdXJyZW50Jz48YSBocmVmPScjJz5Qw6FnaW5hIDEgPC9hPjwvbGk+PGxpPjxhIGhyZWY9JyMnPlDDoWdpbmEgMiA8L2E+PC9saT48L3VsPmQCBQ9kFgICAw9kFgJmD2QWCAIBDw8WAh4HVmlzaWJsZWhkZAIDDw8WAh8CaGRkAgUPDxYCHwJoZGQCCQ8PFgIeD1ZhbGlkYXRpb25Hcm91cAUTUGFnZVZhbGlkYXRpb25Hcm91cGRkAgcPFgIfAmgWAgICD2QWAmYPZBYCAgMPDxYCHgdUb29sVGlwBX9Ow6NvIMOpIHBvc3PDrXZlbCBzdWJtZXRlciBvIGZvcm11bMOhcmlvIGVucXVhbnRvIGV4aXN0aXIgdW1hIHDDoWdpbmEgZGVzdGUgcXVlIG7Do28gc2UgZW5jb250cmEgdG90YWwvY29ycmVjdGFtZW50ZSBwcmVlbmNoaWRhZGRkHyyQApyjTI3oRHUJDqeOpQWXGng=";

        string data = "ctl00_ContentPlaceHolderMain_FormEngine_CONTROL_b34b813223d54739aa270cdc0adf57d1=100&ctl00_ContentPlaceHolderMain_FormEngine_btnSubmit=clicked&__VIEWSTATE=" + viewstate;
        byte[] buffer = Encoding.UTF8.GetBytes(data);
        string proxy = null;


WebRequest req = WebRequest.Create(url);

        byte[] send = Encoding.Default.GetBytes(data);
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = send.Length;

        Stream sout = req.GetRequestStream();
        sout.Write(send, 0, send.Length);
        sout.Flush();
        sout.Close();

        WebResponse res = req.GetResponse();
        StreamReader sr = new StreamReader(res.GetResponseStream());
        string returnvalue = sr.ReadToEnd();

1 个答案:

答案 0 :(得分:0)

为什么不直接从你的某个页面调用Page.Redirect代码块?