[Solved] ASP.Net Routing Error: Error executing child request for

CodeLava
 
on Aug 16, 2021 10:55 PM
Sample_337860.zip
670 Views

I'm writing an application where KYC is required. On page load, I want to query the database from masterpage and check if a users' KYC status is approved.

Is it possible to change the route path of a contentpage from the masterpage i.e instead of Serving the dashboard, they see the KYC page instead, but URL remains the same?

I tried using server.Transfer with threw me errors.

Error executing child request for kyc.aspx

Thank you.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 19, 2021 04:25 AM
on Aug 19, 2021 04:28 AM

Hi CodeLava,

You can use Server.Transfer. But make sure you have specified the page extension (.aspx) in the url.

Check the below example.

HTML

Default

<h1>Default</h1><hr />
<a href='<%=ResolveUrl("~/Customers") %>'>View Customers</a>

Customers

<h1>Customers</h1><hr />
<asp:DataList ID="GridView1" runat="server" RepeatDirection="Vertical">
    <ItemTemplate>
        <table>
            <tr>
                <th colspan="2">
                    <b><%# Eval("Name") %></b>
                </th>
            </tr>
            <tr>
                <td colspan="2">
                    <%# Eval("Id") %><br />
                    <%# Eval("Country")%><br />
                    <asp:Button runat="server" CommandArgument='<%# Eval("ID")%>' OnClick="OnView" Text="View"></asp:Button>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

Home

<h1>Customer Details</h1>
<hr />
<b>Customer Id:</b>
<asp:Label ID="lblCustomerId" runat="server" />

Code

Customers

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[3] {
            new System.Data.DataColumn("Id", typeof(int)),
            new System.Data.DataColumn("Name", typeof(string)),
            new System.Data.DataColumn("Country",typeof(string))
        });
        dt.Rows.Add(1, "John Hammond", "United States");
        dt.Rows.Add(2, "Mudassar Khan", "India");
        dt.Rows.Add(3, "Suzanne Mathews", "France");
        dt.Rows.Add(4, "Robert Schidner", "Russia");
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}

protected void OnView(object sender, EventArgs e)
{
    //Response.Redirect("Customers/" + ((Button)sender).CommandArgument);
    Server.Transfer("Home.aspx?id=" + ((Button)sender).CommandArgument);
}

Home

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        lblCustomerId.Text = Request.QueryString["id"];
    }
}

Screenshot