|
Jinal Desai - LIVE wrote: I think the following line is re-submitting the page.
No no..... You misunderstood. the HTML code I posted was of another page (say Page1.aspx ). And from that I am moving to Default.aspx using Form.Submit()
both page are diffrent, so while going to Default.aspx , I am jumping to it first time ever and so it should give IsPostBack = "False"
|
|
|
|
|
No I think you misunderstand. The html you have shown has the form action as default.aspx and the Javascript is submitting the form which will cause a postback.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: The html you have shown
The HTML I have shown is from Page1.aspx not Default.aspx ....
Both are diffrent .aspx Pages.
From Page1.aspx , I am moving to Default.aspx . Still it will give IsPostBack = "True" at 2nd Page???
|
|
|
|
|
Are you sure? the way I see it, the javascript on his HTML page is submitting the form on that page which, by it's "action" is calling his default.aspx page - and that will not call the postback.
I suspect his problem is that he hasn't properly defined IsPostBack - doesn't he need "Page.IsPostBack" in his If statement? (or Me.IsPostBack or something - sorry, not really conversant with C#)
|
|
|
|
|
See my modified question. This will elaborate my issue better I suppose.
|
|
|
|
|
NeverHeardOfMe wrote: not really conversant with C#
You don't have to be conversant in C#, or VB.NET, IsPostBack is a property of the Page object so you don't specifically need Page.IsPostBack
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
oops, yes - gosh that was dumb of me.
(Hey, it's Monday...)
|
|
|
|
|
See my modified question. This will elaborate my issue better I suppose.
|
|
|
|
|
You don't seem to understand. When navigating to form1.aspx in your browser the page will load, then the javascript will execute causing the form to be submitted. The form action is set to default.aspx so it will receive the postback.
If you want to display default.aspx immediately, then go there. Default.aspx is well, default, IIS should be configured out of the box to go to default.aspx when no other page has been specified in the request.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You know, I hate to be stupid, but... notwiothstanding your perfectly correct point regarding my earlier post, there is someething else going on here. The OP should *not* be getting the PostBack event raised, acording to what he is doing in his post.
His first page posts to the second, but the second page is still being loaded for the first time and is not a post back event.
Just to prove it, I even recreated his pages and (as expected) I did not get the post back... and I can not see why he is....
|
|
|
|
|
Mostly likely we are not being told the complete story by the OP
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You have told the form in page1 that it should always post back to Default.aspx, so when you call the submit function the page posts back to Default. If you want to navigate to Default on post back, get rid of the action="Default.aspx" or change it to page1.aspx, and put a
Response.Redirict("Default.aspx"); in the page load or some other event handler.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
The documentation on IsPostBack is not very good.
Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.
That definition assumes that the only way you are going to get to a page for the first time is through an HTTP GET. The reason being that in ASP.Net they expect pages to post back only to themselves not to other pages.
So the problem you are running into is that the page is both being rendered in response to a postback (from a different page) AND it is the first visit to the page.
|
|
|
|
|
Hi all,
I have few doubts running though my mind which I want to clear. Here is my scenario
let's say I want to create a website for library management.
I need to have registration page where I will allow users to register and login.
My doubt is : After login how do I restrict users from accessing only the authorized page ? also I need to make sure that they should not access pages by entering the url directly without authentication ? i don't want to use the login controls provided in asp.net by default.
Thanks
|
|
|
|
|
Forms Authentication
I think this should cover what you want, it essentially provides an authentication model for you that doesn't have to use .NET login controls, you can use the API to come up with one yourself.
|
|
|
|
|
thanks.. I will look into it.. any other techniques ?
|
|
|
|
|
Dear friends,
I have a linkbutton in gridview. When I click on that linkbutton, I need to get some data based on the row which I clicked and this data to be sent to a javascript function. Please help me how to achieve this. It's very urgent.
Regards,
Cheguri.
|
|
|
|
|
For that you need to use "ItemTemplate" column for your Link Button and write according to following code.
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnCustomerExist"
text="customer exist"
Runat=Server
OnClick="CustomerAlreadyExist"
OnClientClick="return confirmSubmit()"
Width="100″ />
</ItemTemplate>
</asp:TemplateField>
You just need to use LinkButton instead of button.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
This isn't going to help with calling a funciton dependent upon the underlying data row....
Assuming you want to create a specific Javascript call for each row, dependent on (say) the row ID of the underlying dataview, you would do better to use a ButtonColumn:
<asp:ButtonColumn ButtonType="LinkButton" CommandName="doesnt_matter" Text="whatever" />
and add your JavaScript fucntion in the page's head:
function fname(r) {
alert('You clicked row with ID# ' + r);
}
and bind this in the ItemDataBound event:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim dr As DataRow = e.Item.DataItem.Row
Dim js As String
Dim btn As LinkButton = e.Item.Cells(X).Controls(0) ' replace "X" by the appropriate column index
js = "fname(" & CStr(dr("ID")) & ")"; return false;"
btn.Attributes.Add("onclick", js)
End If
NB the extra "return false" statement - this prevents the link-button from posting the entire form back to the server.
btw, OP: re "It's very urgent."
Please don't put this sort of thing in your posts. That is no-one's problem but yours.
|
|
|
|
|
here is my page scenerio.
On page load, i have a web form and a gridview. The gridview displays the xsaction details of the logged in user, (this works gr8)
When I enter details in the web form and click Add. the record should update in the gridview.(this is perfect)
When I click Edit in a row (in the gridview), the row details should populate in the web form (this is also correct)
After I make changes in the web form and click Update, the changes should be updated in the gridview.
(this gives the problem)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Logic;
public partial class Portfolio : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
Includes obj = new Includes();
string str2 = "select A.SCHEME_NAME ,B.SCHEME_NAV ,B.SCHEME_UNITS ,B.AMT_INVESTED ,B.FOLIO_ID FROM NAV A,PORTFOLIO_MASTER B WHERE B.USER_ID='" + Session["user_id"] + "' and b.scheme_id =a.scheme_code";
DataSet ds1 = obj.getDataSet(str2);
GridView1.DataSource = ds1;
GridView1.DataBind();
}
if (Request.QueryString["scheme_name"]!=null)
{
Response.Write(Request.QueryString["scheme_name"]);
Button2.Visible = true;
Button1.Visible = false;
Includes obj4 = new Includes();
string sch_name = Request.QueryString["scheme_name"].ToString();
string str="select scheme_code,scheme_name from nav where scheme_name ="+sch_name +"";
DataSet ds6 = obj4.getDataSet(str);
DataRow dr = ds6.Tables[0].Rows[0];
txt_schname.Text= dr["scheme_name"].ToString();
string s_id=dr["scheme_code"].ToString();
string str1 = "select scheme_nav,scheme_units,amt_invested,folio_id,purchase_date from portfolio_master where scheme_id=" + s_id;
DataSet ds8 = obj4.getDataSet(str1);
DataRow dr1 = ds8.Tables[0].Rows[0];
scheme_nav.Text = dr1["scheme_nav"].ToString();
txt_units.Text = dr1["scheme_units"].ToString();
txt_amt.Text = dr1["amt_invested"].ToString();
txt_folio.Text = dr1["folio_id"].ToString();
txt_purchasedate.Text = dr1["purchase_date"].ToString();
}
if (Session["user_id"] == "")
{
Response.Write(Session["user_id"]);
Response.Redirect("home.aspx");
Session["exp"] = "y";
}
else
{
this.txt_purchasedate.DataBind();
this.ImageButton1.Attributes.Add("onclick", "openPopUp('Cd.aspx')");
txt_amt.Attributes.Add("onkeypress", "return OnlyNums(event,this.value);");
}
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Includes obj3 = new Includes();
float nav = Convert.ToSingle(scheme_nav.Text);
float units = Convert.ToSingle(txt_units.Text);
float amt = Convert.ToSingle(txt_amt.Text);
string folio=txt_folio.Text.Trim();
string remarks = txt_remarks.Text.ToString().Trim();
string po_date = txt_purchasedate.Text.ToString().Trim();
DateTime dt;
dt = Convert.ToDateTime(po_date);
string sc_name = txt_schname.Text .ToString().Trim ();
string str = "select scheme_code,scheme_name from nav where scheme_name='" + sc_name + "' ";
DataSet ds = obj3.getDataSet(str);
DataTable dt1 = ds.Tables[0];
int cnt = dt1.Rows.Count;
string sch_code = "";
for(int i=0;i<cnt;i++)
{
sch_code = dt1.Rows[i]["scheme_code"].ToString().Trim();
}
DateTime dt2 = DateTime.Now;
DateTime dd=new DateTime ();
string s = dt2.ToShortDateString();
dd = Convert.ToDateTime(s);
string str1="insert into portfolio_master values ('"+Session["user_id"]+"','"+sch_code+"',"+nav +","+units +","+amt +",'"+dt +"','"+folio+"','"+remarks +"','" + dd +"')";
obj3.executeQuery(str1);
this.Server.Transfer("portfolio.aspx?update=y");
GridView1.DataBind();
}
protected void ImageButton2_Click2(object sender, ImageClickEventArgs e)
{
Calendar1.Visible = true;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
txt_purchasedate.Text = Calendar1.SelectedDate.ToString();
Calendar1.Visible = false;
}
protected void ImageButton2_Click3(object sender, ImageClickEventArgs e)
{
Calendar1.Visible = true;
}
protected void Edit(object sender, GridViewEditEventArgs e)
{
Includes obj = new Includes();
object obj14 = GridView1.Rows[e.NewEditIndex].Cells[0].Text;
Response.Redirect("portfolio.aspx?scheme_name='" + obj14+"'");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Write(Request.QueryString["scheme_name"]);
Response.Write(Session["user_id"]);
Includes obj22 = new Includes();
string sname = txt_schname.Text.ToString().Trim();
float nav1 = Convert.ToSingle(scheme_nav.Text);
float amt = Convert.ToSingle(txt_amt.Text);
float units = Convert.ToSingle(txt_units.Text);
DateTime dt5;
dt5 = Convert.ToDateTime(txt_purchasedate.Text);
string str4 = "update portfolio_master set scheme_nav= " + nav1 + " where scheme_id in(select scheme_code from nav where scheme_name='" + sname + "')";
obj22.executeQuery(str4);
TextBox1.Text = str4;
GridView1.DataBind();
Button2.Visible = false;
Button1.Visible = true;
Response.Redirect("portfolio.aspx");
}
protected void scheme_nav_TextChanged(object sender, EventArgs e)
{
string ss = scheme_nav.Text.Trim();
Response.Write(ss);
}
}
|
|
|
|
|
You need to Bind Grid once again after database update. Otherwise how Grid comes to know that database is updated and it should show latest data . You need to force it. TO avoid useless postback, try using AJAX.
|
|
|
|
|
_______________________ wrote: this.Server.Transfer("portfolio.aspx?update=y"); GridView1.DataBind();
This is Jumping to portfolio.aspx with IsPostBack = True, So GridView1.DataBind(); below it is never executed. You need to run query once again friend to bring back latest data.
|
|
|
|
|
Hi All,
There is two column in Gridview. First is checkbox and second is textbox.
when i checkbox is check, then textbox visible should be false.
else i have to make textbox visible true.
got it...
if checkbox.checked= true then
textbox.Visible= false
else
textbox.Visible= true
end if
so...problem is i am not getting the event of checkbox...
plz can u send me code..
|
|
|
|
|
DataGridDemo[^] Look at the section titled Checkboxes and Textboxes
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for your replay...
|
|
|
|