Showing posts with label transfer. Show all posts
Showing posts with label transfer. Show all posts

Thursday, March 29, 2012

Pass one variable from one form to other

Hi,

I want to transfer the value of one variable ( basicaly text of a text filed) from one form to other form ...

i tried Server.Transfer("next_form.aspx") ..and then tried Request.Form("text_field") to retrieve it's content .. but doesnt work ...

i also tried Response.Redirect("next_form.aspx") ..and then tried Request.Form("text_field") to retrieve it's content .. but doesnt work ...

I think i am doing it wrong ... how can i do it .. anyone plz help :(

Thanks
imranIn your first form, put the following in your sub that gets called when you submit the form...

Response.Redirect("form2.aspx?myValue=" & myTextBox.Text)

Then in your second page...

Sub Page_Load()
TextBox2.Text = Request.QueryString("myValue")
End Sub
Hi,

When using Server.Transfer its preserveForm arguement to TRUE. This makes viewstate, event procedure available in destination form.

When using Response.Redirect, you can use querystring to pass information to the destination form like Response.Redirect("test.aspx?id=10");

HTH,
Shamir
Also see below article it could helps you

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconpassingservercontrolvaluesbetweenpages.asp

Pass parameter to Popup window

I have 2 webform in vb.NET application.
On Webform1, I have one text box1 and one button.
on Webform2, I have one text box .
I need transfer the value of textbox 1 in webform1 to textbox2 in
webform2. and popup webform2 when user click on the button on webform1.
I have code in webform1:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
End Sub
and following code in webform2:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = Request("a").ToString
End Sub
I could not get the result unless I click on the button1 twice. i know
what happen in here but have no solution. I will be appreciated if you
could help here.
Thanks in advanced,
DiHi ,
You can achieve this by injecting a javascript in the Button1 click
event on the server side . Write an function to inject an javascript in the
webform1 button1 click.
Don't do anything with Attributes of button1 as it won't achieve result u
requires as the 1st page the textbox1 value would be blank.
private void openWindowInjectScript(){
string myScript;
myScript = "<scr" + "ipt>window.open('WebForm2.aspx?a=" + txtIdfield.Value
+ "',null,'height=250, width=250,status= no,resizable= no, scrollbars=no,
toolbar=no,location=no,menubar=no'); </scr" + "ipt>";
this.Page.RegisterStartupScript("JavaScript",myScript);
}
In the webform1.aspx button1_Click event
private void Button1_Click(object sender, System.EventArgs e)
{
openWindowInjectScript();
}
Basically openwindowInjectScript register a script at pageload and which
will make to open an window with current values.
This is the way out for it and it should work
Regards
IntelYogi
"dyw55a@.yahoo.com" wrote:

> I have 2 webform in vb.NET application.
> On Webform1, I have one text box1 and one button.
> on Webform2, I have one text box .
> I need transfer the value of textbox 1 in webform1 to textbox2 in
> webform2. and popup webform2 when user click on the button on webform1.
> I have code in webform1:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
> TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
> resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
> End Sub
> and following code in webform2:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> TextBox1.Text = Request("a").ToString
> End Sub
>
> I could not get the result unless I click on the button1 twice. i know
> what happen in here but have no solution. I will be appreciated if you
> could help here.
> Thanks in advanced,
> Di
>
Thank you for your reply. But actually I tried and this did not work
for some reason, any idea?
Try this onClick event of your button
Response.Write("<SCRIPT>");
Response.Write("window.open('page,aspx?value=" + myval +
" ',null,'height=200,width=900,status=yes,
toolbar=no,menubar=no,location=no')
;
");
Response.Write("</SCRIPT>");
I think this will do the trick, tell me if not
dyw55a@.yahoo.com wrote in message news:<1117647067.875660.133640@.g43g2000cwa.googlegroups.c
om>...
> Thank you for your reply. But actually I tried and this did not work
> for some reason, any idea?

Pass parameter to Popup window

I have 2 webform in vb.NET application.
On Webform1, I have one text box1 and one button.
on Webform2, I have one text box .
I need transfer the value of textbox 1 in webform1 to textbox2 in
webform2. and popup webform2 when user click on the button on webform1.

I have code in webform1:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
End Sub

and following code in webform2:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = Request("a").ToString
End Sub

I could not get the result unless I click on the button1 twice. i know
what happen in here but have no solution. I will be appreciated if you
could help here.

Thanks in advanced,
DiHi ,
You can achieve this by injecting a javascript in the Button1 click
event on the server side . Write an function to inject an javascript in the
webform1 button1 click.
Don't do anything with Attributes of button1 as it won't achieve result u
requires as the 1st page the textbox1 value would be blank.

private void openWindowInjectScript(){
string myScript;
myScript = "<scr" + "ipt>window.open('WebForm2.aspx?a=" + txtIdfield.Value
+ "',null,'height=250, width=250,status= no,resizable= no, scrollbars=no,
toolbar=no,location=no,menubar=no'); </scr" + "ipt>";
this.Page.RegisterStartupScript("JavaScript",myScript);
}

In the webform1.aspx button1_Click event
private void Button1_Click(object sender, System.EventArgs e)
{
openWindowInjectScript();
}
Basically openwindowInjectScript register a script at pageload and which
will make to open an window with current values.

This is the way out for it and it should work

Regards
IntelYogi

"dyw55a@.yahoo.com" wrote:

> I have 2 webform in vb.NET application.
> On Webform1, I have one text box1 and one button.
> on Webform2, I have one text box .
> I need transfer the value of textbox 1 in webform1 to textbox2 in
> webform2. and popup webform2 when user click on the button on webform1.
> I have code in webform1:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
> TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
> resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
> End Sub
> and following code in webform2:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> TextBox1.Text = Request("a").ToString
> End Sub
>
> I could not get the result unless I click on the button1 twice. i know
> what happen in here but have no solution. I will be appreciated if you
> could help here.
> Thanks in advanced,
> Di
>
Thank you for your reply. But actually I tried and this did not work
for some reason, any idea?
Try this onClick event of your button

Response.Write("<SCRIPT>");
Response.Write("window.open('page,aspx?value=" + myval +
"',null,'height=200,width=900,status=yes,toolbar=no ,menubar=no,location=no');
");
Response.Write("</SCRIPT>");

I think this will do the trick, tell me if not

dyw55a@.yahoo.com wrote in message news:<1117647067.875660.133640@.g43g2000cwa.googlegroups. com>...
> Thank you for your reply. But actually I tried and this did not work
> for some reason, any idea?
i'd tried both suggest solutions from Yogi, but it seems not work for me...is any solution yet?

the prob is...webform2's page_load will be run 1st b4 the button_click event run...so any wisdom can help up?

From http://www.developmentnow.com/g/8_2...opup-window.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Monday, March 26, 2012

Pass value to second DropDownList from the first one

I want pass value to 2nd DropDownList from 1st one. I use "DropDownList1.SelectedValue", but got error message." can't transfer data type from varchar,..." Yes, in Database, it is varchar type.

Here is a source code:

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string sql = "select Address from myTable where Name=" + DropDownList1.SelectedValue ;
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "myTable");
DataView dv=ds.Tables [0].DefaultView ;

DropDownList2.DataTextField="Address";
DropDownList2.DataValueField ="Address";
//DropDownList2.DataSource =ds.Tables[0].DefaultView;
DropDownList2.DataSource=dv;
DropDownList2.DataBind ();

con.Close();
}

Two things.

1) I would use a SqlDataReader to populate the DropDownList. It is 100x faster than a DataSet.

2) Try DropDownList1.SelectedItem.Value to get the value of the DropDownList


move your datasource code line above both your datatextfield and datavaluefield

[edit]

He is right about the speed--much faster.


I did try: DropDownList1.SelectedItem.Value, but got same error msg.

You are missing the single quotes around the parameter, try:

string sql = "select Address from myTable where Name='" + DropDownList1.SelectedValue + "'" ;


Better NOW.