.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Get the CommandArgument in the Page_Load?

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

Hi All,

Here is my problem:

I have created a custom user control allowing to display a ListView of LinkButtons.

Code inline:

 <asp:ListView ID="ListView" runat="server">
                    <ul id="Ul1" runat="server">
                        <li id="ItemPlaceholder" runat="server"></li>
                    <asp:DataPager runat="server" ID="DataPager" PageSize="30">
                            <asp:NumericPagerField ButtonCount="10"

View Complete Post

More Related Resource Links

Page_Load Order -- Inserting a record

Is there any way to make sure an Insert Command happens before the Page_Load Events? I'm having a problem with inserting, then reading the DataSet directly after.  It seems it processes too quickly, or prior to the record being inserted. It has an impact on the DataSet that is to be displayed on screen. Summary:  Page_Loads > Finds Saved Data > If None exists (string contains 2 types of matches) > Displays the 1 of 2 types randomly. Buttons 1 & 2 Insert their respective options > Page Posts Back > Page_Loads > Read Saved Data > If my Max amount of the 1 of 2 types of Data are reached, the remaining type is shown > Displayed on page The problem I am having is that my DisplayDataSet is not getting the correct values.  It seems it's always 1 record behind on the count, because the count happens so fast, it's not getting the record that was just inserted. How can I write this, or make sure the "Find Saved Data' Routine happens after the Insert has been preformed?  Imports System.Data Imports System.Data.SqlClient Partial Public Class Assessment1 Inherits System.Web.UI.Page Protected Sub btnINS1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnINS1.Click Dim connetionString As String Dim connection As SqlConnection Dim adapter As New SqlDataAdapter Dim s

FormView clearing value I set in page_load.

I have a page with a FormView on it. The page is strictly for adding records to a Table. I have the FormView bound to an EntityDataSource and everything works greate except for one thing. I want to initialize a date field in the FormView to today's date. So, in my page_load event I have:               if (!Page.IsPostBack)            {                //Initialize SetupDate to today.                TextBox setupdate = (TextBox)fvJob.FindControl("txtSetupDate");                setupdate.Text = DateTime.Now.ToShortDateString();            } The first time this page loads, the txtSetupDate field is initialized. Although, and subsequent loads of the page doesn't initialize the Text Box. I step through the code in the debugger and I can see that the code is executig, but something (the FormView bind?) is "clearing" the Text Box. Any ideas? Why does it work on the first load, but not subsequent ones? Thanks for any help!  

while changingMode page_load data not showing....

Hi... i am having insertpage.aspx where i am fetching systemdate but when i am changingMode in for data Insert, systemdate not showing that time and same as EditMode also. I am sending codebehind code .....please help me out..... /*********************************************************/ using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using VehicleApp.library; public partial class InsertPage : System.Web.UI.Page {     library lib = new library();     protected void Page_Load(object sender, EventArgs e)     {         if (!IsPostBack)         {             BindFormView();             Label mydate = (Label)VehicleFormView.Row.FindControl("dateLabel");             mydate.Text = DateTime.Now.Date.ToShortDateString();         }     }     private void BindFormView()     {         if (Session["strTemp"] != null)  &nb

How to fill a formview at page_load?

I have a formview and I want to fill it at page_load. The formview must show the data of the person that has logged in.So the question is how can I fill the formview so that is shows the data of the right person (UserId = @Param2) so that the formview is in editmode?This is the code for the Formview:<asp:FormView ID="FormView1" runat="server" DataKeyNames="UserId" DataSourceID="MySQLProfielDataSource"> <ItemTemplate> <asp:Table id="ItemTabel" runat="server"> <asp:TableRow> <asp:TableCell> UserId: </asp:TableCell> <asp:TableCell> <asp:Label ID="UserIdLabel" runat="server" Visible="false" Text='<%# Eval("UserId") %>' /> </asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell> Geslacht: </asp:TableCell> <asp:TableCell> <asp:Label ID="Gesla

Call parent window Page_Load when child closes

 I have a popup window that I open using  window.showModalDialog('Popup.aspx'); The client enters some information and then clicks a 'Save' button on the Popup window.  At that point I want the popup window to close and refresh the parent window which I though would execute the page_load event on the parent window. Here is the code that I have for the button click on the popup window. window.returnValue = true; window.close(); The popup window closes and it seems like the parent refreshes, but the page_load event on the parent is not called.  I put in a breakpoint to verify.  I need the page_load event to execute.   Thanks in advance for your help, JZ

Sub Page_Load - not working in the content page.

Hi there,I am using a content page (tellafriendaction.aspx) which uses a master page (PublicMaster.Master)The masterpage Page_Load event (in the code behind page) is working and is called when tellafriendaction.aspx page is called.But the Page_Load event in the content page (tellafriendaction.aspx) is not working or is not called when i call the content page while i am debugging the application.(Note: I have an html form in TellAFriend.aspx content page. It submits the form to TellAFriendAction.aspx page, which should capture the form content and send the friend an email message.)Here is some code samples:=================tellafriendaction.aspx.vb (code behind page for the content page)==================Imports System.ConfigurationImports System.WebImports System.Web.SecurityImports System.Web.UIImports System.Web.UI.WebControlsImports System.Web.UI.HtmlControlsImports System.Net.MailPartial Class tellafriendaction    Inherits System.Web.UI.Page    Sub Page_Load 'this method is not being called WHY?        Dim emailFromAddress As String = Master.Request.Form("txtFromEmailAddress")        Dim emailToAddress As String = Master.Request.Form("txtToEmailAddress")        Dim fromName As String = Master.Request.Form("txtFromName")   &nb

__doPostBack() with button calling page_load twice


Hi all,

I have explicitly added __doPostBack() on Button onclientClick event .

 <asp:Button ID="Button1" runat="server" Text="Button" 

When I am clicking the button the Page_Load is calling twice.

But if I am adding below code inside page load ,page load is calling only once on button click.

Button1.Attributes.Add("onClientClick", "__doPostBack('Button1','')");

Again if i add with return false it is giving me it calling only once page load on click

 <asp:Button ID="Button1" runat="server" Text="Button" 
         OnClientClick="__doPostBack('Button1','');return false;"/>

and return true is giving me again twice page load ,but adding return true or false in attribute.add code is giving the same result ,only one page load call.

Button1.Attributes.Add("onClientClick", "__doPostBack('Button1','');return true;");

I am not able to understand what is going on exactly I try to add __doPostBack in differ

Page_Load() events running before event methods.


Iv come across this problem a few times.

As a simple example:

Why is when creating a simply Visual web part with a button onclick method, the page_load() event always fires before the event that caused the page to refresh (in this case the button onclick())?


This has become very anoying, one way iv found to over come this is to save any data i require within the application memory then reload it again within the method i activated if it exists.


This seems very time consuming.


Surely theres a way to stop this?




Page_Load Issue


Hi ,

I have two ddl's that is populated based on another. As the Admin.. I am able to select any branch and get the result on the other ddl. However , my users(since they are only authorized to see one branch), are not able to see the result. I tried to bind the sql statement on my page_load but it does nothing. the first ddl is set to autopostback so as an admin i can change branches. but for my users, it only shows one branch(Which sould be the way it should be) and the result is blank . Any ideas on how i can do this. Thanks in Advance

How to disable User Control page_load



I have a user control (ascx) which is part of a web form page (aspx). I would like that the page_load of the ascx file is not run in some situations. Is there any way I can disable running the page_load on the fly?

Thanks in advance


Page_Load executes twice with AJAX


I noticed in my web site that the Page_Load event executes twice so I created a new web form that includes a ScriptManager, an AJAX Update Panel and a button. Also, I added code to the Page_Load event which write a message to a log file. After the button is clicked, I check the log file and I get 2 records. After this first test, I removed the ScriptManager and the AJAX UpdatePanel and let the button alone. I clicked it once more and checked the log file which has only one record. So my conclusion is that, when the web form is AJAX enabled the Page_Load event executes twice; if the web form IS NOT AJAX enabled the Page_Load event executes only once. The following is the code for such en event:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Tools.NewEvent("I am in Page_Load", "", "", "", "", "", "")
End Sub


Why is this happening?
Is there a way to prevent it?

Jorge Maldonado

TableRows added on Page_Load not available on Button_Click



I'm dynamically adding rows at run-time in the Page_Load function as it pulls data from a database to populate them. However, in my "btnSubmit_Click" function, if I call tblMassEntry.Rows.Count, the total is 0.

The table is created on the .aspx page.

Can someone please help me?



How to store seesion values in page_load



I am new to dotnet.

I have two pages

First one is registration page.second one is Gridview page.

When i click on submitt button,the data will store in gridview.

If i want to update the data,click edit button.it will navigate to registration page with concer data.

I wrote code in first page as

            <td align="right">

                <asp:Label ID="lblUserId" runat="server" Font-Bold="True" 
                    ForeColor="Blue" Text="ClientId"></asp:Label>
            <td class="style4">
                <asp:TextBox ID="txtUserId" runat="server" Width="150" 
                    ontextchanged="txtUserId_TextChanged" AutoPostBack="True"></asp:TextBox>
            <asp:Label ID="lblUiddisplay" runat="server" Text="Label" ForeColor="Green" 
                    Font-Bold="True" Visible="False" ></asp:Label>
                <asp:RequiredFieldValidator ID="rfvUserId" runat="server" 
                    ControlToValidate="txtUserId" Er
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend