Wednesday, March 21, 2012

Passing varibles.

1. Here is my dilemma. I am passing variable ~name.aspx?name=32

I can generate the detailview based on that variable, however if I want '32' to stay in the insert mode it just doesn't show. How could I pass varibles from grit to detailview insert mode

2.In CF you call passed variable as #name#, how do you do it here I wanted lable to show the #name# but I just don't know how to do such simple task in asp.net I tried <%= name %> nothing happened..

3.Any tutorials on nice webforms?

you can use: Request.QueryString["name"].

since the 'name" variable is in the qury string and not inside the page class, you have to use the Request object.

Hope this helps,

Vivek


vivek_iit:

you can use: Request.QueryString["name"].

since the 'name" variable is in the qury string and not inside the page class, you have to use the Request object.

Hope this helps,

Vivek

Great, but where exacly do I place that line of code? If I do as follows it doesn't show the verible

<asp:LabelID="Label2"runat="server"Style="z-index: 103; left: 873px; position: absolute;

top: 156px"Text='Request.Querystring["name"]'Width="154px"></asp:Label>


vivek_iit:

you can use: Request.QueryString["name"].

since the 'name" variable is in the qury string and not inside the page class, you have to use the Request object.

Hope this helps,

Vivek

Great, but where exacly do I place that line of code? If I do as follows it doesn't show the verible

<asp:LabelID="Label2"runat="server"Style="z-index: 103; left: 873px; position: absolute;

top: 156px"Text='Request.Querystring["name"]'Width="154px"></asp:Label>


No, you have to use it like:

<% Request.Querystring["name"] %>

Or better use it in code behind as:

//page load method

if(!Request.Querystring["name"]==null)

string name =Request.Querystring["name"].ToString();

Hope this helps,

Vivek


Vivek, Ido appriciate your time. I entered as follows

<asp:LabelID="Label2"runat="server"Style="z-index: 103; left: 873px; position: absolute;

top: 157px"Text='<% Request.Querystring[name] %>'Width="154px"Height="19px"></asp:Label>

Unfortunatly it doesn't show anything. No returns of any value.

Could you provide with sometype code example that you know works. It is frustraiting that such a basic thing take so much time.

Thanks for your help


Vivek, I just found out that if I use html <input> instead of <asp:TextBox then it works like a charm.

Question then, how do I enter values for asp forms. Do you know of any artical that makes this clearer. Any way this is my code

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

Test: <%= Request.QueryString["dem_id"] %> // This works

<asp:TextBoxID="TextBox1"runat="server"Text='<% Request.QueryString["dem_id"] %>'></asp:TextBox>// This Doesn't work

<inputid="Text1"type="text"value='<%= Request.QueryString["dem_id"] %>'/> // This works

</asp:Content>


There is a difference b/w web server controls and HTML controls, note that in the asp textbox control the Id is "Textbox1" but in the query string variable you are using "dem_id", why are you doing that?

Also, refer these links for details:

http://authors.aspalliance.com/aspxtreme/sys/Web/HttpRequestClassQueryString.aspx

http://www.codeproject.com/aspnet/QueryString.asp

If still there are any issues, let me know, I'll write some sample code so that your doubts are cleared.

HTH,

Vivek


I agree with Vivek, if you want to have the asp label set with a querystring, it's easiest to do it in the code-behind in your Page_Load()

String str;
if ((str = Request.QueryString["name"]) != null)
{
Label2.Text = str;
}

Hope this helps.


vivek_iit:

There is a difference b/w web server controls and HTML controls, note that in the asp textbox control the Id is "Textbox1" but in the query string variable you are using "dem_id", why are you doing that?

Also, refer these links for details:

http://authors.aspalliance.com/aspxtreme/sys/Web/HttpRequestClassQueryString.aspx

http://www.codeproject.com/aspnet/QueryString.asp

If still there are any issues, let me know, I'll write some sample code so that your doubts are cleared.

HTH,

Vivek

Vivek, following is the entire page. What am I missing? could you rewrite it.

<%@.PageLanguage="C#"MasterPageFile="~/test.master"Title="Untitled Page"Debug="false" %><%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxToolkit" %>

<%@.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Namespace="System.Web.UI"TagPrefix="asp" %>

<scriptrunat="server">

publicclassWebForm2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label Lable2;protected System.Web.UI.WebControls.TextBox TextBox1;

privatevoid Page_Load(object sender, System.EventArgs e)

{

this.Lable2.Text = Request.QueryString["dem_id"];

this.TextBox1.Text = Request.QueryString["dem=id"];

}

}

</script>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<scriptlanguage="javascript"type="text/javascript">

</script>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

Test: <%= Request.QueryString["dem_id"] %> <-- this one works

<inputid="Text1"type="text"value='<%= Request.QueryString["dem_id"] %>'/> <-- this one works

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox> <-- this one doesn't work

<asp:LabelID="Label2"runat="server"></asp:Label> <-- this one doesn't work

</asp:Content>


I have modified the page_load method a little bit:

privatevoid Page_Load(object sender, System.EventArgs e)

{
if(!Request.QueryString["dem_id"]==null)
{

this.Lable2.Text = Request.QueryString["dem_id"].ToString();
this.TextBox1.Text = Request.QueryString["dem_id"].ToString();;
}
}

Just make sure that you indeed have a query string variable in the address bar in the browser like:http://localhost/myapp/mypage.aspx?dem_id=45

Hope this helps,

Vivek


This is what I gotCompiler Error Message:CS0023: Operator '!' cannot be applied to operand of type 'string'

Source Error:

 
Line 28:        {
Line 29:
Line 30:            if (!Request.QueryString["dem_id"] == null)
Line 31:            {
Line 32:                this.Lable2.Text = Request.QueryString["dem_id"].ToString();

I deleted the line 'if' since it checks if the string has any characters. I will run the page and still nothing will show.

Why am I drilling this? I am using VS2005 to create a DB driven website. ASP has nice easy to implement features however such simple, basic thing gives so much trouble. Maybe there is a better way of doing this but than how?

Maybe sessions? They all reflect using standard html with ASP nested. But what if I wanted to use ASP tags?

Following is the code on the page

<scriptrunat="server">publicclassWebForm2 : System.Web.UI.Page { protected System.Web.UI.WebControls.Label Lable2; protected System.Web.UI.WebControls.TextBox TextBox1; privatevoid Page_Load(object sender, System.EventArgs e) { this.Lable2.Text = Request.QueryString["dem_id"].ToString(); this.TextBox1.Text = Request.QueryString["dem_id"].ToString(); } }</script> <asp:ContentID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server"><scriptlanguage="javascript"type="text/javascript"> </script> <asp:ScriptManagerID="ScriptManager1"runat="server"> </asp:ScriptManager> Test:<%= Request.QueryString["dem_id"]%> //Works <inputid="Text1"type="text"value='<%= Request.QueryString["dem_id"]%>'/> //works <asp:TextBoxID="TextBox1"runat="server"></asp:TextBox> //Doesn't work <asp:LabelID="Label2"runat="server"></asp:Label> //Doesn't work

</asp:Content>


Hope this reads better

Compiler Error Message: CS0023: Operator '!' cannot be applied to operand of type 'string'

Source Error:

 
Line 28:        {
Line 29:
Line 30:            if (!Request.QueryString["dem_id"] == null)
Line 31:            {
Line 32:                this.Lable2.Text = Request.QueryString["dem_id"].ToString();

I deleted the line 'if' since it checks if the string has any characters. I will run the page and still nothing will show.

Why am I drilling this? I am using VS2005 to create a DB driven website. ASP has nice easy to implement features however such simple, basic thing gives so much trouble. Maybe there is a better way of doing this but than how?

Following is the code on the page

<scriptrunat="server">

publicclassWebForm2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label Lable2;protected System.Web.UI.WebControls.TextBox TextBox1;

privatevoid Page_Load(object sender, System.EventArgs e)

{

this.Lable2.Text = Request.QueryString["dem_id"].ToString();

this.TextBox1.Text = Request.QueryString["dem_id"].ToString();

}

}

</script>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<scriptlanguage="javascript"type="text/javascript">

</script>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

Test: <%= Request.QueryString["dem_id"] %>

<inputid="Text1"type="text"value='<%= Request.QueryString["dem_id"] %>'/>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<asp:LabelID="Label2"runat="server"></asp:Label>

</asp:Content>


That error message is because you're applying the NOT ( ! ) to the Request.QueryString operation instead of the whole line QueryString == null. Either say:

if ( ! (Request.QueryString["dem_id"] == null)) or say if (Request.QueryString["dem_id"] != null)

personally I would say that if you want the querystring to be put into a variable of some sort, then just say:

if((myStr = Request.QueryString["dem_id"]) != null)

that way you check for the querystring and assign it to a variable in one line. Thats just me though.

/edit Also I forgot to mention, if you run the page and nothing shows up from the querystring, try entering the URL you want directly into your IE (or whatever you're using) address bar. Like if it starts running your page and it says your address is http://whatever/yourpage.aspx then manually add the querystring value and type into the address bar: http://whatever/yourpage.aspx?dem_id=32 and then go to that page and it should show up.

Hope this helps.


<scriptrunat="server">

publicclassWebForm2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label Lable2;

protected System.Web.UI.WebControls.TextBox TextBox1;

string myStr;privatevoid Page_Load(object sender, System.EventArgs e)

{

if ((myStr = Request.QueryString["dem_id"]) !=null)

{

this.Lable2.Text = Request.QueryString["dem_id"].ToString();

this.TextBox1.Text = Request.QueryString["dem_id"].ToString();

}

}

}

</script>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<scriptlanguage="javascript"type="text/javascript">

</script>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

Test: <%= Request.QueryString["dem_id"] %>

<inputid="Text1"type="text"value='<%= Request.QueryString["dem_id"] %>'/>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<asp:LabelID="Label2"runat="server"></asp:Label>

</asp:Content>

I implamented your changes and manually added the querystring. HTML markup works ASP doesn't.

0 comments:

Post a Comment