|
Hi
I would like to know how to construct a query string with JavaScript and to then be able to access the passed values in the code behind. Can someone show me how?
Thanks
|
|
|
|
|
AndyASPVB wrote: how to construct a query string with JavaScript
What does it mean?
Yes, if are able to create the string, you can save the string in server side hidden field and then can access it from codebehind.Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Hi,
You can try this:
function QueryString(qs)
{
s = location.href;
s = s.replace("?","?&").split("&");
re = "";
for(i=1;i<s.length;i++)
{
if(s[i].indexOf(qs+"=")==0)
{
re = s[i].replace(qs+"=","");
}
}
return re;
}
then you can do sth to access the pass to anywhere.
modified 27-May-14 4:49am.
|
|
|
|
|
A similar thing is done in XMLHttpRequest...GET method to be more specific!
create a URL with query stings and call it. Access the querystrings using Request.QueryString["QSName"]
|
|
|
|
|
Hi
I am almost there, but I am getting a problem with multiple postbacks. You see, I need to have my javascript function on an asp:panel scrollbar, and in my js, I wrote this:
function scrollPos(position)
{
window.location.href="default.aspx?scrollPos="+position.scrollTop;
}
When I move the scrollbar, the page constantly posts back in an uncontrollable manner, flickering away! How do I stop this, so it is smooth and the page is workable?
|
|
|
|
|
|
Hi
I have already looked at the maintain scroll bar position and this only works on the browser scroll bar and not on asp:panel. Plus I actually have a number of panels which could all be in different positions, which is why I need to use JS and query strings
|
|
|
|
|
Sorry, but just to add, my web page refreshes every few minutes. Therefore, is it possible to have the query string parameters attached to the url then when the page is posted back?
|
|
|
|
|
Hello -
I want to change the forecolor of a label in a gridview I have, depending on the text in that label.
I can't access the label by the ID in the code-behind to get the properties.
The label is part of templatefield:
<div>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Server.HtmlEncode(Eval("FirstName").ToString())%>'></asp:Label>
</div>
Thx, Lazialemodified on Monday, March 15, 2010 3:54 PM
|
|
|
|
|
You wont get the label just by ID.To change the color, Just find the label in RowDataBound event of gridview and change the style there.
Find the label as
Label lblFirstName= (Label)e.Item.FindControl("lblFirstName");
put this RowDataBound event and modify the style as per your requirement.Cheers!!
Brij
modified on Tuesday, March 16, 2010 12:54 AM
|
|
|
|
|
can you give me some example how I can do ItemDataBound event?
Thanks for your help
|
|
|
|
|
laziale wrote: can you give me some example how I can do ItemDataBound event?
I guess this should be RowDataBound . Not ItemDataBound !
Please check the answer that I have posted.
Thanks !Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
lets compromise on:
For Gridview its RowDataBound and for DataGrid its ItemDataBound !
|
|
|
|
|
I don't know if he has made some changes in his original post or not. It may be because Brij asked him to use ItemDataBound
Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
I just removed the
<templatefield> and <itemtemplate> tags because of some formatting issue of the site .
|
|
|
|
|
There are many data controls in asp.net and and have the different event names .for the same cause Was just a typo Cheers!!
Brij
|
|
|
|
|
Please Correct the formatting of your post. Its breaking the page ! Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Try with this :
You need to do this in RowDataBound Event of GridView .
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblFirstName= (Label)e.Item.FindControl("lblFirstName");
if(lblFirstName.Text == "MyText")
lblFirstName.ForColor=mycolor;
}
} Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Thanks for all your help.
I have one question, since I am trying to figure out the color of the label in the page_load event, is there anyway how I can assign the color depending from the text in that label?
Thx, Laziale
|
|
|
|
|
laziale wrote: since I am trying to figure out the color of the label in the page_load event, is there anyway how I can assign the color depending from the text in that label?
Why you are trying out in Page_Laod. If you want to check for each and every row of gridview, you need to check it in RowDataBound Event only.Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
cause I want to display the proper color before the site is rendered on the screen. Is there a way how I can trigger that event in the Page_Load?
Thanks, Laziale
|
|
|
|
|
Do you understand the page life cycle? Read about it here[^].
In your page load event you want to set the DataSource property of your grid and call DataBind. Hopefully in your init method you setup an item data bound event handler. When DataBind is called, for each row being added to the gridview your data bound event handler will be called. There you set your colors. After all of that is done, Render gets called for the page which generates all the HTML from your page and code which gets sent to your user's browser.Don't blame me. I voted for Chuck Norris.
|
|
|
|
|
For changing the color,just change the color in rowdatabound only.It'll suffice your purpose.
After pageload,you must have assigning some datasource.then, your rowdatabound event will be called for each row.In this event,you can modify the color based on the text. After it page will render and your changes will refelct on the screen.
So you dont need to do this at pageload.Cheers!!
Brij
|
|
|
|
|
nothing is happening with that one, I have the event set but its not triggered at all. The page loads without triggering that event.
But thanks for your help anyway.
Laziale
|
|
|
|
|
laziale wrote: nothing is happening with that one, I have the event set but its not triggered at all.
Did you specified the event with gridview in aspx page ?Cheers !
Abhijit
Codeproject MVP
|
|
|
|